PDA

View Full Version : Visual Basic Question


AdmiralZ
09-18-2005, 04:05 PM
Ok, obviously we have some programmers here, so I'd like to know something, if anyone can help me.

In VB, say I have a variable "intNumber", and its value is "0".

I also have a button called "cmdAddone".

What do I put inside the button's code to get it to add "1" to "intNumber"?

Basically what I am trying to do here is get a program to display a number and then add one onto it every time you click the button. How do I do that?

baron
09-18-2005, 04:24 PM
hope this helps you:



Dim intNumber As Integer
Private Sub cmdAddone_Click()

intNumber = intNumber + 1

Label1.Caption = intNumber
End Sub

AdmiralZ
09-18-2005, 04:39 PM
In the form load sub I had declared the variable as "2005".
Otherwise, that's what I had, but whenever I press the button, the label just goes to "1" and then when I press the button again, it doesn't change.

baron
09-18-2005, 05:04 PM
im not exactly sure what you mean but...

i put the "Dim intNumber As Integer" in the 'general' part of the coding

and

if you mean if you set the varible to something different..like 2005

you needa put "intNumber=2005" in the command button code i think



edit:


that works..the way i think you want it?

Dim intNumber As Integer

Private Sub command1_Click()



intNumber = intNumber + 1

Label1.Caption = intNumber

End Sub

Private Sub Form_Load()
intNumber = 2004
End Sub

AdmiralZ
09-18-2005, 05:45 PM
Thanks, that worked.