QB64 Phoenix Edition
Question on ln in a for/next loop - Printable Version

+- QB64 Phoenix Edition (https://qb64phoenix.com/forum)
+-- Forum: QB64 Rising (https://qb64phoenix.com/forum/forumdisplay.php?fid=1)
+--- Forum: Code and Stuff (https://qb64phoenix.com/forum/forumdisplay.php?fid=3)
+---- Forum: Help Me! (https://qb64phoenix.com/forum/forumdisplay.php?fid=10)
+---- Thread: Question on ln in a for/next loop (/showthread.php?tid=3026)

Pages: 1 2


Question on ln in a for/next loop - Dimster - 09-12-2024

Not sure why this is throwing an error

    For ln = 1 To 50
        Print ln, SpeedFactor(ln), Speed(ln)
    Next

The error line is the For ln = 1 to 50. The error reads "Unsupported variable used in the For statement"

The "l" in the "ln" is a lower case L and not the number 1.

If I change it to For n = 1 to 50, it's fine ... no error



The other curious thing about this is, if the loop was just to Print the value of  "ln" (ie For ln = 1 to 50: Print ln: Next) it runs fine, no error. So is the error actually the loop control "ln" or is it balking at the other two .. SpeedFactor(ln) or Speed(ln) both of which are correctly calculated prior to this print routine.

Again, this is not a big deal, all I need to do is change the loop control to just n,  just curious why


RE: Question on ln in a for/next loop - Petr - 09-12-2024

is that all there is in the loop? Can you insert the loop here? The way you describe it is untraceable. Is there by any chance a pointer value (image or sound) or a MEM field assigned to the variable ln in the loop?


RE: Question on ln in a for/next loop - LEM - 09-12-2024

Could it be that ln is referring to/reserved for the natural logarithm?  I doesn't seem like that is immediately the case in QB64PE (where the natural logarithm is LOG) (and I think it is LOG in C++ too), but still...

Just throwing that out there as a possibility...


RE: Question on ln in a for/next loop - SMcNeill - 09-12-2024

Look for what you have ln defined as.   Check DIM and _DEFINE type statements.

The  "Unsupported variable used in the For statement" is usually one that triggers when you use an invalid variable type for the FOR..LOOP, such as a STRING variable..

Code: (Select All)
Dim ln As String
For ln = 1 To 50
' Print ln, SpeedFactor(ln), Speed(ln)
Next



RE: Question on ln in a for/next loop - TerryRitchie - 09-12-2024

(09-12-2024, 07:01 PM)SMcNeill Wrote: Look for what you have ln defined as.   Check DIM and _DEFINE type statements.

The  "Unsupported variable used in the For statement" is usually one that triggers when you use an invalid variable type for the FOR..LOOP, such as a STRING variable..

Code: (Select All)
Dim ln As String
For ln = 1 To 50
    ' Print ln, SpeedFactor(ln), Speed(ln)
Next
I was thinking along this same line earlier but if this were the case then removing the arrays from the print statement and having it work means ln is a number in his case. This is a strange error he is receiving.


RE: Question on ln in a for/next loop - SMcNeill - 09-12-2024

Pasted as is, it works in the IDE for me.  Best way to get something like this fully identified and looked into, is to zip up the file and resources (if necessary) and share them on the forums here so we can dig into it deeper. 

There's not a lot of things which generate that type of error message for us, so I'm thinking a variable mismatch is coming into play somewhere/somehow with things, but it's hard to prove/test without having the actual code in front of you.


RE: Question on ln in a for/next loop - PhilOfPerth - 09-12-2024

Probably a red herring, but in Java, .in  denotes  data being input, as distinct from .out for  output


RE: Question on ln in a for/next loop - bplus - 09-13-2024

@Dimster you are NOT showing all the code, there is no error until default 10 index is exceeded by undim'd arrays.

maybe fun to keep everyone guessing what you aren't showing?


RE: Question on ln in a for/next loop - Dimster - 09-13-2024

Way, way too many lines of code to display here, but I think I may have found the problem, seem I used "ln" as a loop control in an obscure subroutine where I had "ln" again as a loop control variable but in that subroutine I had an "exit for", so maybe it was carrying over the last loop value of "ln". Then again, the "ln" should have been a local variable, I have not Dim Shared it so I wouldn't have thought to initialize it to zero before the printing of SpeedFactor and Speed. 

It's ok you guys, this is not a big deal. I do appreciate the feed back and if it happens again, as the song goes " I'll stay on the bus, forget about us, put the blame on me" it's an easy error to overcome and keep on coding.


RE: Question on ln in a for/next loop - bplus - 09-13-2024

(09-13-2024, 02:46 PM)Dimster Wrote: Way, way too many lines of code to display here, but I think I may have found the problem, seem I used "ln" as a loop control in an obscure subroutine where I had "ln" again as a loop control variable but in that subroutine I had an "exit for", so maybe it was carrying over the last loop value of "ln". Then again, the "ln" should have been a local variable, I have not Dim Shared it so I wouldn't have thought to initialize it to zero before the printing of SpeedFactor and Speed. 

It's ok you guys, this is not a big deal. I do appreciate the feed back and if it happens again, as the song goes " I'll stay on the bus, forget about us, put the blame on me" it's an easy error to overcome and keep on coding.

OK, probably not, but by any chance did you pass ln to the sub which will pass back changed if of same same type, main and subroutine?

name that tune: Tie A Yellow Ribbon Around The Old Oak Tree

Can you name the singer who made it famous?