• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

Why doesn't this work? (VB 6.0 question)

NTB

Diamond Member
MAXGENERATIONS=10,000 (constant declared at begining of program)

Generations = 10,000 (default; set when program starts)

Private Sub cmdGenerations_Click() 'allows user to change # of generations

Generations = InputBox("Enter number of generations:" & _
vbCrLf & "(Max = " & MAXGENERATIONS & ")", _
"Generations", MAXGENERATIONS)

If Generations < 1 Or Generations > MAXGENERATIONS Then Generations = MAXGENERATIONS

End Sub

If I input a negative number or a number > 10000, it stays there. The if statement should catch it and change it to 10k, but for some reason it doesn't. Any ideas?

Nate
 
Originally posted by: MrChad
You're missing an "End If"

Don't need it for a single-line if. In fact, sticking an end-if in there spits out a compile error: end if without block if
 
It seems to work for me, although in my test program, I have Generations and MaxGen declared within the function. Maybe it has something to do with the scope of your variables. How did you declare the global variables?
 
Originally posted by: igowerf
It seems to work for me, although in my test program, I have Generations and MaxGen declared within the function. Maybe it has something to do with the scope of your variables. How did you declare the global variables?

It does work - I just tried it in it's own, independent little program. Time to look elsewhere; it must be something else somewhere in the program. The question now is, where?. 😕
 
Originally posted by: igowerf
How are you outputting the value of Generations? Is there another function that changes its value?

It is used in two other areas: once to control a loop, and once to set an ouput color for something on the screen. The loop is For gen = 1 to Generations; the output one looks like this: ColorNum = Generations Mod 6.

I don't think either of these are affecting it, or I would be getting some really weird results. The program works perfectly if I put in anything >=1. If I put in anything less, it just acts like nothing happened. I can click on the Generations button and set it to another number, and it's ready to go.

Nate
 
Back
Top