|
-
May 19th, 2000, 07:25 AM
#1
Thread Starter
New Member
i feel like an idiot posting this, but i want a label to increase by one. I used this and for some reason it doesn't work.
Code:
Private Sub Form_Load()
Dim k As Integer
End Sub
Private Sub tmr_Timer()
k = k + 1
lbl.Caption = k
End Sub
it only goes up to one and stops
-
May 19th, 2000, 08:37 AM
#2
Fanatic Member
Try this instead:
--------------------------------
Private Sub tmr_Timer()
Static K as Integer
k = k + 1
lbl.Caption = k
End Sub
--------------------------------
Static will make it keep its value. The way you had it tells the timer that k is 0 therefore you have:
0 = 0 + 1
This will work. Trust me.
-
May 19th, 2000, 08:45 AM
#3
Hello there,
You need to either use the static keyword ok declare a variable that can be seen either globaly (not the best) or in a form level.
In the form declaration section, so it can be used by the all subs and function in the form:
Code:
Option Explicit
' form vars
Dim iCounter As Integer
or in a bas file
Code:
Option Explicit
' Public var's
Dim piCounter As Integer
or with the static
Code:
Private Sub tmr_Timer()
Static k
k = k + 1
lbl.Caption = k
End Sub
Hope this helps,
-
May 19th, 2000, 09:44 AM
#4
Thread Starter
New Member
It worked.
tnx. i used the static one from RealisticGraphics, the other one was too long
-
May 20th, 2000, 02:07 AM
#5
Hyperactive Member
Why bother with static? you can just as easily put
at the top of the code, outside of any subs. That's where you can define integers or API or constants for the form.
bob
-
May 20th, 2000, 02:39 AM
#6
Fanatic Member
Using static is better for one good reason. You can type everything in the same spot. Plus if you want to use the var again later you can. Static is a very usful property that you can use rather than going back and forth to declare vars elsewhere. But it's more of a preference than anything else.
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
|