groberts1980
New member
- Joined
- Feb 7, 2004
- Messages
- 2
Im writing a program for the VB class Im taking, and Ive run into a problem. Basically, I need the program to count how many times a button is clicked, and display the results when another button is pressed. Here is the code I have for the Driving Range button, the one to be counted:
Static intDrivingRange As Integer
intDrivingRange += 1
My professor requires that all our declerations be local, which is why Im using static instead of a dim statement in the declerations section. These lines should add 1 to the integer DrivingRange each time the button is clicked. My problem is getting it to display the results when the Results button is clicked. Heres my code for the Results Button:
Static intDrivingRange As Integer
lblDrivingRange.Text = "Driving Range: " & (intDrivingRange)
When I click the Driving Range button a few times, then click the Results button, it always says "Driving Range: 0"
The part I cant figure is if I move the lblDrivingRange.text line into the same procedure as the counter, it keeps a running total as Im clicking Driving Range button and works fine. But for the project I need it to simply keep count until I hit the Results button. Only then should it display the results.
Is my problem with the counter or the way Im trying to display the results?
- groberts1980
P.S. Using class-level variables does work for this program. My problem is, at this stage, my professor wants us to use only local variables. There are 6 buttons I need counters for, and when I Dim all 6 variables at the class level, the program works fine. But like I said I have to use local variables. Is there any way to create the variable locally in the DrivingRange button procedure, and have the Results button use that variable and its value? If I have to turn in the program using class level variables I will, but I would prefer to have it work using only local variables. I know what youre thinking, there are probably many VB professors out there who are better than the one I got, but Im stuck with him. Ergo, Im stuck being told to use only local variables.
Static intDrivingRange As Integer
intDrivingRange += 1
My professor requires that all our declerations be local, which is why Im using static instead of a dim statement in the declerations section. These lines should add 1 to the integer DrivingRange each time the button is clicked. My problem is getting it to display the results when the Results button is clicked. Heres my code for the Results Button:
Static intDrivingRange As Integer
lblDrivingRange.Text = "Driving Range: " & (intDrivingRange)
When I click the Driving Range button a few times, then click the Results button, it always says "Driving Range: 0"
The part I cant figure is if I move the lblDrivingRange.text line into the same procedure as the counter, it keeps a running total as Im clicking Driving Range button and works fine. But for the project I need it to simply keep count until I hit the Results button. Only then should it display the results.
Is my problem with the counter or the way Im trying to display the results?
- groberts1980
P.S. Using class-level variables does work for this program. My problem is, at this stage, my professor wants us to use only local variables. There are 6 buttons I need counters for, and when I Dim all 6 variables at the class level, the program works fine. But like I said I have to use local variables. Is there any way to create the variable locally in the DrivingRange button procedure, and have the Results button use that variable and its value? If I have to turn in the program using class level variables I will, but I would prefer to have it work using only local variables. I know what youre thinking, there are probably many VB professors out there who are better than the one I got, but Im stuck with him. Ergo, Im stuck being told to use only local variables.