Timer As A Loop Ender?!?!?
Hey,
For Ill tell you what this code is trying to do...
It counts to as much as it can, as fast as it can all adding up to n the variable. But when the Timer's Interval = 10000 it should end.
Any way to do this? btw... I will make the timer's action do something else later, just for now i wrote that
Thanks :D I'm not very good at loops, my loops keep making my vb crash :eek2:
gl! :wave:
VB Code:
Private Sub Command1_Click()
Dim n As String
Let n = 1
Do Until Interval = 10000
Picture1.Cls
Picture1.Print n + 1
loop
End Sub
Private Sub Timer1_Timer()
Unload Form1
End Sub
Re: Timer As A Loop Ender?!?!?
Hmm... Interesting idea.
Try this:
VB Code:
Dim lngCurrentInterval As Long
Private Sub Form_Load()
lngCurrentInterval = 1
End Sub
Private Sub Command1_Click()
Dim n As String
Let n = 1
Do Until lngCurrentInterval = 10000
Picture1.Cls
Picture1.Print n + 1
Loop
End Sub
Private Sub Timer1_Timer()
lngCurrentInterval = lngCurrentInterval + 1
End Sub
Not shure if that is whathats all I can think of at this moment :)
Cheers,
RyanJ
Re: Timer As A Loop Ender?!?!?
Quote:
Originally Posted by Brin
Hey,
For Ill tell you what this code is trying to do...
It counts to as much as it can, as fast as it can all adding up to n the variable. But when the Timer's Interval = 10000 it should end.
Any way to do this? btw... I will make the timer's action do something else later, just for now i wrote that
Thanks :D I'm not very good at loops, my loops keep making my vb crash :eek2:
gl! :wave:
VB Code:
Private Sub Command1_Click()
Dim n As String
Let n = 1
Do Until Interval = 10000
Picture1.Cls
Picture1.Print n + 1
loop
End Sub
Private Sub Timer1_Timer()
Unload Form1
End Sub
Your code would never end, unless you exit the do loop. Besides, Interval is a (not-defined) variable. If you want to ask for the timer's property you should say so: Timer1.Interval. Anyway... I don't see you're changing this value, so... if the Interval is not 10000 your loop will simply never end.
Re: Timer As A Loop Ender?!?!?
Quote:
Originally Posted by sciguyryan
Hmm... Interesting idea.
Try this:
VB Code:
Dim lngCurrentInterval As Long
Private Sub Form_Load()
lngCurrentInterval = 1
End Sub
Private Sub Command1_Click()
Dim n As String
Let n = 1
Do Until lngCurrentInterval = 10000
Picture1.Cls
Picture1.Print n + 1
Loop
End Sub
Private Sub Timer1_Timer()
lngCurrentInterval = lngCurrentInterval + 1
End Sub
Not shure if that is whathats all I can think of at this moment :)
Cheers,
RyanJ
This prints '2's for about 25 seconds, then crashes
Re: Timer As A Loop Ender?!?!?
Ehh Yup...
I got another program... I have my vb 5.0 book right over here, the problem is im using vb 6. Still it should work since 5.0 is older then 6.0 right?
VB Code:
Private Sub Command1_Click()
Dim n As String
Let n = 1
Let Timer1_Timer.Enabled = True
Do Until Timer1.Interval = 10000
Picture1.Print n + 1
Loop
End Sub
Private Sub Timer1_Timer()
Load Form2
Form2.Show
Picture2.Print "Congrats! Your computer counted to "; n; " In 10 seconds!"
Unload Form1
End Sub
My vb doesn't recognise this
VB Code:
Let Timer1_Timer.Enabled = True
Higlights Timer1_Timer And Says
"Expected fuction or variable."
Hmm?!?!?!
Re: Timer As A Loop Ender?!?!?
The Let keyword is no longer needed - it was mostly used in the older versions of the language :)
Try:
VB Code:
Private Sub Command1_Click()
Dim n As String
n = 1
Timer1_Timer.Enabled = True
Do Until Timer1.Interval = 10000
Picture1.Print n + 1
Loop
End Sub
Private Sub Timer1_Timer()
Load Form2
Form2.Show
Picture2.Print "Congrats! Your computer counted to "; n; " In 10 seconds!"
Unload Form1
End Sub
Cheers,
RyanJ
Re: Timer As A Loop Ender?!?!?
Hmm.... tried it but it still gives me the same error?
Re: Timer As A Loop Ender?!?!?
what is setting the interval, and when is it changing?
Re: Timer As A Loop Ender?!?!?
No wonder why it cannot recognize "Timer1_Timer.Enabled". The object's name is Timer1, not Timer1_Timer. Besides... you're not understanding how a timer works. The Interval's property is explained as:
Quote:
Returns/sets the number of milliseconds between calls to a Timer control's Timer event.
You won't get the Interval property incremented each second it passes. Re-write your code. That won't work.
Re: Timer As A Loop Ender?!?!?
Something like this would be better.
VB Code:
Private Sub Command1_Click()
Timer1.Interval = 1000
dim x as integer, n as integer
x=0
timer1.enabled = true
do while x<11
debug.print n
n=n+1
loop
end sub
private sub timer1.timer
x=x+1
end sub
Re: Timer As A Loop Ender?!?!?
Hey dglienna, just saw your post while posting.. I got another code it works with the timer, not just with n + 1 and so on....
VB Code:
Private Sub Command1_Click()
Dim n As String
n = 1
Timer1.Enabled = True
Do Until Timer1.Interval = 10000
'Picture2.Print "Congrats! Your computer counted to "; n + 1; " In 10 seconds!"
Loop
End Sub
Private Sub Timer1_Timer()
Picture2.Print "Congrats! Your computer counted to "; n; " In 10 seconds!"
Timer1.Enabled = False
End Sub
Re: Timer As A Loop Ender?!?!?
That WON'T WORK. for the same reasons we've been saying.
Look at my code. That is how to use the timer. The way you are trying will not END. EVER!
Re: Timer As A Loop Ender?!?!?
Quote:
Originally Posted by Brin
Hey dglienna, just saw your post while posting.. I got another code it works with the timer, not just with n + 1 and so on....
VB Code:
Private Sub Command1_Click()
Dim n As String
n = 1
Timer1.Enabled = True
Do Until Timer1.Interval = 10000
'Picture2.Print "Congrats! Your computer counted to "; n + 1; " In 10 seconds!"
Loop
End Sub
Private Sub Timer1_Timer()
Picture2.Print "Congrats! Your computer counted to "; n; " In 10 seconds!"
Timer1.Enabled = False
End Sub
Brin, did you read any of my posts? There are several things wrong. Do you understand what I state in each post. If you don't, ask. But, what you're doing is still wrong.
Re: Timer As A Loop Ender?!?!?
Ok, I tried what you said...
VB Code:
Private Sub Command1_Click()
Timer1.Interval = 1000
Dim x As Integer, n As Integer
x = 0
Timer1.Enabled = True
Do While x < 11
Debug.Print n
n = n + 1
Loop
End Sub
Private Sub timer1_timer()
x = x + 1
End Sub
btw... vb 6.0 doesnt accept private sub names which have . in them... And after each name there has to be a () either with something in it or left blank...
So when I do the upper code I get an overflow error.
I see that the code that you wrote relies on the error to happen hence
but rather then printing the variable n it prints Overflow error
Re: Timer As A Loop Ender?!?!?
The code needed several corerctions.
VB Code:
Option Explicit
Private x As Integer
Private Sub Command1_Click()
Timer1.Interval = 1000
Dim n As Long
x = 0
Timer1.Enabled = True
Do While x < 11
Debug.Print n
n = n + 1
DoEvents
Loop
Timer1.Enabled = False
End Sub
Private Sub Timer1_Timer()
x = x + 1
End Sub
Re: Timer As A Loop Ender?!?!?
Sorry, I thought you were just looking at the method. I wrote it in the editor.
My mistake.
Re: Timer As A Loop Ender?!?!?
Yup...Works like a charm :)
And I looked at the back of me book, "DoEvents", nice command, learned something new :D
btw... I added a picture2.print so it would work too if an error didnt occur, which doesn't in mine, the first time i tried...
Again, Thanks! All :D Ill rate yer posts in an hour, gotta go somewhere
bbs(BeBackSoon)
:wave:
VB Code:
Option Explicit
Private x As Integer
Private Sub Command1_Click()
Timer1.Interval = 1000
Dim n As Long
x = 0
Timer1.Enabled = True
Do While x < 11
Debug.Print n
n = n + 1
DoEvents
Loop
Picture2.Print "Congrats! Your computer counted to "; n; " In 10 seconds!"
Timer1.Enabled = False
End Sub
Private Sub Timer1_Timer()
x = x + 1
End Sub
AGain, THANKS!!!!