|
Post by angusmann on Jun 2, 2008 9:02:55 GMT -5
Hi all. I think this is a new bug.
If you declare a variable as global, then use it in a for/next loop within a subroutine it generates this error message :
Runtime Error in program 'untitled': Message not understood: #lessFromInteger:
The code below will generate the error :
global x call testsub print "Finished." end
sub testsub print "Starting subroutine." for x=1 to 10 print x next x end sub
|
|
|
Post by mackrackit on Jun 2, 2008 10:02:00 GMT -5
Not sure if what you ran across is a bug... Try this: global x x = 3 call testsub print "Finished." end
sub testsub print "Starting subroutine." for i=1 to 10 x=x+1 print x next i end sub
I put the x = 3 in so you can see it is a global.
|
|
|
Post by StefanPendl on Jun 2, 2008 10:11:05 GMT -5
This is not a new issue, but it was only reported for Liberty BASIC currently.
You might have your reasons to use a global variable for a FOR..NEXT index, but I would never use one, since they are temporary.
|
|
|
Post by carlgundel on Jun 2, 2008 11:24:18 GMT -5
It's a bug in the sense that hard errors like that are always bugs. -Carl Not sure if what you ran across is a bug... Try this: global x x = 3 call testsub print "Finished." end
sub testsub print "Starting subroutine." for i=1 to 10 x=x+1 print x next i end sub
I put the x = 3 in so you can see it is a global.
|
|
|
Post by angusmann on Jun 2, 2008 21:23:32 GMT -5
This is not a new issue, but it was only reported for Liberty BASIC currently. You might have your reasons to use a global variable for a FOR..NEXT index, but I would never use one, since they are temporary. Good advice; I recognize that. Personally I never use globals in this way but I declared one as global as part of a debugging process. I just wanted the calling routine to be able to see if the subroutine got to the end of the for-next loop. The easy way was to (temporarily) declare it global. But instead of making bug-checking easier it added an extra bug!
|
|
|
Post by StefanPendl on Jun 3, 2008 3:15:20 GMT -5
I just wanted the calling routine to be able to see if the subroutine got to the end of the for-next loop. The easy way was to (temporarily) declare it global. You can assign the last value of index to a global variable. The index will be one more than the upper limit of the loop. global gx call testsub print gx print "Finished." end
sub testsub print "Starting subroutine." for x=1 to 10 print x next x gx = x end sub
|
|