AdmiralZ Posted September 18, 2005 Share Posted September 18, 2005 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? Link to comment Share on other sites More sharing options...
baron Posted September 18, 2005 Share Posted September 18, 2005 hope this helps you: Dim intNumber As Integer Private Sub cmdAddone_Click() intNumber = intNumber + 1 Label1.Caption = intNumber End Sub Link to comment Share on other sites More sharing options...
AdmiralZ Posted September 18, 2005 Author Share Posted September 18, 2005 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. Link to comment Share on other sites More sharing options...
baron Posted September 18, 2005 Share Posted September 18, 2005 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 Link to comment Share on other sites More sharing options...
AdmiralZ Posted September 18, 2005 Author Share Posted September 18, 2005 Thanks, that worked. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.