|
Post by drfloyd on Jun 10, 2019 15:42:00 GMT -6
In traditionnel Basic, to "fill" an array i do that :
dim name$(50) restore dataname for i=1 to 50 read name$(i) next .dataname data "rocky","henri","paul","roger"....
what if the equivalent in RC please ?
thanks
|
|
|
Post by tbird on Jun 10, 2019 17:10:40 GMT -6
I don't believe you can do that in RC, you would have to load the array manually or type them in a file and read them in. I am 95% sure about it. n00b may have something else.
|
|
|
Post by n00b on Jun 10, 2019 18:03:43 GMT -6
You just need some creativity data_lib.bas dim data$ dim data_index data_index = 0
function read$() if data_index >= length(data) then return "" end if dim s$ dim c$ dim i for i = data_index to length(data)-1 c = mid(data, i, 1) if c = "," then if (i+2) >= length(data) then data_index = length(data) else data_index = i+1 end if exit for elseif (i+1) = length(data) then data_index = length(data) s = s + c exit for end if s = s + c data_index = data_index + 1 next return trim(s) end function
sub restore() data_index = 0 end sub
example.bas data$ = "rocky, henri, paul, roger"
dim name$[4] restore
for i = 0 to 3 name[i] = read next
|
|
|
Post by johnno56 on Jun 10, 2019 18:06:17 GMT -6
I've tried using the old method of reading data lines. Placing the data before and after the read loop without success. I have opted for the 'external' file option. Who says that Basic doesn't have its quirks? lol
J
|
|
|
Post by tbird on Jun 10, 2019 18:51:22 GMT -6
n00b well that was a nice solution, thank you for the post. johnno56 Basic is as quirky as it's users
|
|
|
Post by johnno56 on Jun 10, 2019 20:06:53 GMT -6
Ouch! lol
|
|
|
Post by drfloyd on Jun 11, 2019 4:16:18 GMT -6
a DATA command is really missing
Thanks for your function ! Is this working : ?
data$ = "rocky,12,145,henri,24,163,paul,33,150,roger,16,180" dim name$[4] dim age[4] dim score[4] restore for i = 0 to 3 name = read age=read score=read next
ok?
not cool anyway, as i have thousand of data to declare
better an external file perhaps... but if external file, the data is readable by everybody
|
|
|
Post by n00b on Jun 11, 2019 6:05:11 GMT -6
I fixed your example. The Read() function I made returns a string. You need to use the Val() function to convert it to a number. You can find out more by reading through the "Variables and Data Types" and "Arrays" sections in the manual.
data$ = "rocky,12,145,henri,24,163,paul,33,150,roger,16,180" dim name$[4] dim age[4] dim score[4] restore
for i = 0 to 3 name[i] = read age[i] = val(read) score[i] = val(read) next
|
|
|
Post by drfloyd on Jun 11, 2019 13:23:03 GMT -6
Stupid error Thanks
|
|