|
Post by metro on Jan 10, 2020 0:39:15 GMT -5
A lot of head scratching going on here! For the life of me I could not work out why an array would not print when looping through within a Sub
my index was "z", so changed it to "q" and everything worked then I found that "z" was declared as GLOBAL, so I changed the GLOBAL "z" to GLOBAL "q" and the array would not print again
is this a known issue, and I'm just showing my ignorance again?
EDIT changed Example code below to demonstrate ...just remove the rem before global to see the effect
' GLOBAL q Call Doit
WAIT
SUB Doit call LoadList$ call Add2ListView END SUB
SUB Add2ListView
for q= 1 to 3 print Rowdata$(q) next END SUB
SUB LoadList$ Rowdata$(1) =" A2M,AAC,ABC,AGI,AGL,AGL,AHG,ALG,ALL,ALQ,ALU,AMC,ANN,ANZ,AOG,APA,APC,APT,APX,AST,ASX,XJO" Rowdata$(2)="AWC,AYS,AZJ,BAL,BAP,BEN,BHP,BKL,BLD,BOQ,BPT,BRG,BSL,BXB,CAR,CBA,CCL,CCP,CDD,CGC,CGF,CHC" Rowdata$(3)="CIM,CMW,CPU,CRS,CSL,CTD,CTX,CWN,CWY,DCN,DLX,DMP,DOW,DXS,EHE,EVN,FBU,FLT,FMG,FWD,FXJ,GDX"
open "text.txt" for output as #1 for q = 1 to 3 #1 Rowdata$(q) next close #1
q=1 open "text.txt" for input as #2 WHILE not(eof(#2)) line input #2, newline$ Rowdata$(q)= newline$ q=q+1 WEND maxRows=q CLOSE #2
END SUB
|
|
|
Post by Rod on Jan 10, 2020 4:46:28 GMT -5
No ignorance on your part, just lost resources making life difficult. Yes it was recorded as a low priority bug. This from the old bug wiki.
FOR loop counter is not updated if global
Description If a loop counter of a FOR loop is declared as global, it does not update inside the procedure the counter is used.
Example code to demonstrate the bug. global count count = 200 print print "Counter befor procedure ... "; count call procedure print print "Counter after procedure ... "; count end sub procedure print print "Counter at beginning of procedure ... "; count print for count = 1 to 10 print "Counter inside loop ... "; count next print print "Counter at end of procedure ... "; count end sub
Example code to work around the bug. global count count = 200 print print "Counter befor procedure ... "; count call procedure print print "Counter after procedure ... "; count end sub procedure print print "Counter at beginning of procedure ... "; count print for i = 1 to 10 count = i print "Counter inside loop ... "; count next print print "Counter at end of procedure ... "; count end sub
|
|
|
Post by metro on Jan 10, 2020 4:47:56 GMT -5
Thanks Rod, for a while I thought I was one step closer to senility
|
|
|
Post by tsh73 on Jan 10, 2020 5:26:14 GMT -5
I think it used to be know issue global used as FOR loop (in my tests here) does not actually change in FOR loop. But still counts.
Interesting.
global i i = 3 print "i=";i print "in loop 1 to 5" for i = 1 to 5 print "i=";i next
i = 3 print "i=";i print "in a sub - loop 1 to 5" call test
sub test for i = 1 to 5 print "i=";i next end sub
i=3 in loop 1 to 5 i=1 i=2 i=3 i=4 i=5 i=3 in a sub - loop 1 to 5 i=3 i=3 i=3 i=3 i=3
|
|