|
-
Apr 18th, 2005, 02:40 PM
#1
Thread Starter
Lively Member
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 I'm not very good at loops, my loops keep making my vb crash
gl!
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
Last edited by Brin; Apr 18th, 2005 at 06:23 PM.
-
Apr 18th, 2005, 02:47 PM
#2
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
-
Apr 18th, 2005, 02:57 PM
#3
Need-a-life Member
Re: Timer As A Loop Ender?!?!?
 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  I'm not very good at loops, my loops keep making my vb crash
gl!
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.
Emiliano F. Martín
If a post has helped you then please Rate it! (and give the user points he/she deserves by clicking on the image).
Encourage the person who helped you to keep doing it, and give him the points he deserves.
MP3 Organizer: Freeware to logically organize all your MP3s.
-
Apr 18th, 2005, 03:08 PM
#4
Re: Timer As A Loop Ender?!?!?
 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
-
Apr 18th, 2005, 03:24 PM
#5
Thread Starter
Lively Member
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?!?!?!
-
Apr 18th, 2005, 03:28 PM
#6
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
-
Apr 18th, 2005, 03:33 PM
#7
Thread Starter
Lively Member
Re: Timer As A Loop Ender?!?!?
Hmm.... tried it but it still gives me the same error?
-
Apr 18th, 2005, 03:34 PM
#8
Re: Timer As A Loop Ender?!?!?
what is setting the interval, and when is it changing?
-
Apr 18th, 2005, 03:34 PM
#9
Need-a-life Member
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:
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.
Emiliano F. Martín
If a post has helped you then please Rate it! (and give the user points he/she deserves by clicking on the image).
Encourage the person who helped you to keep doing it, and give him the points he deserves.
MP3 Organizer: Freeware to logically organize all your MP3s.
-
Apr 18th, 2005, 03:42 PM
#10
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
-
Apr 18th, 2005, 03:47 PM
#11
Thread Starter
Lively Member
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
-
Apr 18th, 2005, 03:54 PM
#12
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!
-
Apr 18th, 2005, 03:54 PM
#13
Need-a-life Member
Re: Timer As A Loop Ender?!?!?
 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.
Emiliano F. Martín
If a post has helped you then please Rate it! (and give the user points he/she deserves by clicking on the image).
Encourage the person who helped you to keep doing it, and give him the points he deserves.
MP3 Organizer: Freeware to logically organize all your MP3s.
-
Apr 18th, 2005, 04:06 PM
#14
Thread Starter
Lively Member
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
-
Apr 18th, 2005, 04:16 PM
#15
Need-a-life Member
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
Emiliano F. Martín
If a post has helped you then please Rate it! (and give the user points he/she deserves by clicking on the image).
Encourage the person who helped you to keep doing it, and give him the points he deserves.
MP3 Organizer: Freeware to logically organize all your MP3s.
-
Apr 18th, 2005, 04:19 PM
#16
Re: Timer As A Loop Ender?!?!?
Sorry, I thought you were just looking at the method. I wrote it in the editor.
My mistake.
-
Apr 18th, 2005, 04:26 PM
#17
Thread Starter
Lively Member
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
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 Ill rate yer posts in an hour, gotta go somewhere
bbs(BeBackSoon)
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!!!!
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
|