DATA
-
- Posts: 37
- Joined: Jan 26, 2017 7:54
DATA
Is there any way to use select case or something to correspond with integers in DATA lines?
For example:
say I have
DATA 1,3,1,5,1,1,1,5,3,2,3,1
can I use something like:
Select Case FieldCorresponding
case 1:
grass
case 2:
snow
case 3:
mud
case 4:
sand
case 5:
cement
End Select
For example:
say I have
DATA 1,3,1,5,1,1,1,5,3,2,3,1
can I use something like:
Select Case FieldCorresponding
case 1:
grass
case 2:
snow
case 3:
mud
case 4:
sand
case 5:
cement
End Select
Re: DATA
There is a bit more effort needed:
Code: Select all
DATA 1,3,1,5,1,1,1,5,3,2,3,1
Dim As String texture(1 To 5) ' whatever size needed
Dim As Byte rByte
' initialize array of string
For ReadIndex As UInteger = 1 To 5
Read rByte ' get a DATA Byte
Select Case As Const rByte ' recode straight away
Case 1 : texture(ReadIndex) = "grass"
Case 2 : texture(ReadIndex) = "snow"
Case 3 : texture(ReadIndex) = "mud"
... ' extend as needed
End Select
Next
Re: DATA
For small array's, you can also initialize it, straight away:
Code: Select all
Dim As String texture(1 To 5) => { "grass", "snow", "mud", "sand", "cement" }
Re: DATA
Just another idea.
To watch what`s going on "behind", uncomment the line 18 (??) == 'REM'
Adi
Code: Select all
'Corresponding.bas
' the "DATA" could be read from a file as well...
DATA "1,3,1,5,1,1,1,5,3,2,3,1,0" ' added "0" as ´stopper´ :) Adi
Dim myStr As String
Read mystr ' = DATA
Dim FieldCorresponding As Long
Print MyStr
For i As Integer=1 To Len(MyStr) Step 2
' expl.. VAL stops converting as soon as a nun-numeric
' character is encountered. NonValid always is 0=zero
' so better start NOT at 0(zero), but with 1 as the
' first valid choice
'REM' Print i & " : " & Mid(myStr,i,2) & " ";
FieldCorresponding=Val(Mid(myStr,i))
' can I use something like:
Select Case FieldCorresponding
Case 1:
Print "grass"
Case 2:
Print "snow"
Case 3:
Print "mud"
Case 4:
Print "sand"
Case 5:
Print "cement"
' default:
Case Else:
Print "n/a:" & i & "==" & FieldCorresponding
End Select
Next i
sleep
Adi
Re: DATA
Adele's code shows an alternate method of reading the data.
It converts the data statement integers into one comma delimited string and then walks through the string.
If you uncomment the rem line you can see each character as it is processed.
It converts the data statement integers into one comma delimited string and then walks through the string.
If you uncomment the rem line you can see each character as it is processed.
-
- Posts: 37
- Joined: Jan 26, 2017 7:54
Re: DATA
I think I already know the answer to this question, but can I change variable's in a DATA statement during runtime?
Say: DATA "1,3,1,1,1,4,2" to DATA "1,2,2,4,2,1,2"
If I remember correctly I can't but I just thought I'd ask anyway.
Say: DATA "1,3,1,1,1,4,2" to DATA "1,2,2,4,2,1,2"
If I remember correctly I can't but I just thought I'd ask anyway.
Re: DATA
What you're having in DATA are Constants (which are then, read into variables).
So, no changes to anything in DATA possible, at run-time.
So, no changes to anything in DATA possible, at run-time.
Re: DATA; change DATA variables
Hi,
The coding style with DATA is, let us say, _very_ traditional :)
Nevertheless, in some cases more readable than other constructs
Adi
try:TurtleProgrammer wrote: ... but can I change variable's in a DATA statement during runtime?
Say: DATA "1,3,1,1,1,4,2" to DATA "1,2,2,4,2,1,2"
Code: Select all
' read statements, just an example
restore D_LABEL1:
read i1,i2,i3,i4,i5,i7 ' or whatever
restore D_LABEL2:
read i1,i2,i3,i4,i5,i7 ' or whatever
' other code....
' please don`t run into this "code"...
' the DOC says this might be dangerous
D_LABEL1:
DATA 1,3,1,1,1,4,2
D_LABEL2:
DATA "1,2,2,4,2,1,2"
Nevertheless, in some cases more readable than other constructs
Adi