|
-
Aug 14th, 2007, 02:51 AM
#1
Thread Starter
Lively Member
Incrementing a number
This should be incredibly simple, and I don't know why I can't figure it out. I want my form to count the number of times a button has been clicked. As far as I can tell, Visual Basic has no increment operator, which is really stupid.
vb Code:
Private Sub Form_Load()
Dim intCounter As Integer
intCounter = 0
End Sub
Private Sub Command1_Click()
intCounter = intCounter + 1
End Sub
I've also tried different operators that work in other programming languages, such as intCounter++ and intCounter+=1, but none of them seem to work. Why doesn't this work? It's embarrassing that I can't figure this out.
-
Aug 14th, 2007, 03:00 AM
#2
Re: Incrementing a number
The way you're incrementing the number is correct. It's how you've declared your variable. Try this 
vb Code:
'Delcare this at the top of your form
Dim intCounter As Integer
Private Sub Form_Load()
intCounter = 0
End Sub Private
Sub Command1_Click()
intCounter = intCounter + 1
End Sub
-
Aug 14th, 2007, 03:08 AM
#3
Re: Incrementing a number
Use Option Explicit in order to minimize occurrence, if not totally avoid, such errors.
-
Aug 14th, 2007, 04:02 AM
#4
Thread Starter
Lively Member
Re: Incrementing a number
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|