Visual Basic Code , VB.NET Code, VB Code
  Home   :  Code   :  Forums   :  Submit   :  Mailing List   :  About   :  Contact


Quick Basic Sleep Statement Equivilent?


Quick Basic Sleep Statement Equivilent?

Author
Message
CDRIVE
CDRIVE
Forum God
Forum God (103K reputation)Forum God (103K reputation)Forum God (103K reputation)Forum God (103K reputation)Forum God (103K reputation)Forum God (103K reputation)Forum God (103K reputation)Forum God (103K reputation)Forum God (103K reputation)

Group: Forum Members
Posts: 548, Visits: 2.6K
It really isn't important to me what you called it. It creates the delay I needed and that's  important to me. BTW, I never thought that your sub was an API.

Thanks,

Chris

________________________________________________________________ 

"So much to learn. So little time to do it. Wise men know it's later than one thinks"!

Mark's Syntax.Zip    Pause Sub

I don't answer programming questions via PMs. That's what the forum is for! 

waynespangler
waynespangler
Forum God
Forum God (97K reputation)Forum God (97K reputation)Forum God (97K reputation)Forum God (97K reputation)Forum God (97K reputation)Forum God (97K reputation)Forum God (97K reputation)Forum God (97K reputation)Forum God (97K reputation)

Group: Forum Members
Posts: 910, Visits: 5.4K
I should have called it "Delay" but I used the word "Sleep" because that was what it is called in QB.

It is a sub and not an api. You will probably get an error if you declare the api.

Sorry for any misconceptions.

Wayne

I know enough to be dangerious.

It is hard to understand how a cemetery can raise its burial rates and blame it on the cost of living.

CDRIVE
CDRIVE
Forum God
Forum God (103K reputation)Forum God (103K reputation)Forum God (103K reputation)Forum God (103K reputation)Forum God (103K reputation)Forum God (103K reputation)Forum God (103K reputation)Forum God (103K reputation)Forum God (103K reputation)

Group: Forum Members
Posts: 548, Visits: 2.6K
I added a semicolon to the print statement in the above code so the CRLF would be supressed and the count would print accross the Form instead of down the Form. I haven't found a simple way of doing this in a Label though. When I substitute a Label for my print medium it overwrites the previous count. Can someone point me in the right direction? I want to append the text in the Label, not overwrite it.

Thank you,

Chris

________________________________________________________________ 

"So much to learn. So little time to do it. Wise men know it's later than one thinks"!

Mark's Syntax.Zip    Pause Sub

I don't answer programming questions via PMs. That's what the forum is for! 

CDRIVE
CDRIVE
Forum God
Forum God (103K reputation)Forum God (103K reputation)Forum God (103K reputation)Forum God (103K reputation)Forum God (103K reputation)Forum God (103K reputation)Forum God (103K reputation)Forum God (103K reputation)Forum God (103K reputation)

Group: Forum Members
Posts: 548, Visits: 2.6K
Perhaps as a neophyte I use the wrong terms? I know that I liked the Sleep statement in QB an used it for effects. Wayne's code enabled me to create a variable named Sleep and use it in much the same way & location that it would be in QB. I didn't use the API call that you suggested because you said that it stops everything on the computer for the specified time. Perhaps I misunderstood you.

Thanks,

Chris

________________________________________________________________ 

"So much to learn. So little time to do it. Wise men know it's later than one thinks"!

Mark's Syntax.Zip    Pause Sub

I don't answer programming questions via PMs. That's what the forum is for! 

Keithuk
Keithuk
Forum God
Forum God (298K reputation)

Group: Moderators
Posts: 1.9K, Visits: 5.5K
CDRIVE (2/6/2007)
Keith, what can I say? I'm the novice here. I only know what I see. What I see is the following:

Sleep = 1     ' Print statement (prints) executes every second.

Sleep = 0.5  ' Print statement (prints) executes every 500mS.

Sleep = 60   ' Print statement (prints) executes every minute.

Wayne's code is simulating the QB SLEEP statement perfectly! I wish I could somehow register "Sleep" with VB and call it like any other VB statement. I'll register it as a Sub though.

Well if you look at the code again Chris what I see is no =

Wayne's code isn't simulating the GB Sleep because he is using Option Explicit and a Sleep Sub not the Sleep API.

Keith

I've been programming with VB for 17 years. Started with VB4 16bit Pro, VB5 Pro, VB6 Pro/Enterprise and now VB3 Pro. But I'm no expert, I'm still learning.

Edited
2/7/2007 by Keithuk
CDRIVE
CDRIVE
Forum God
Forum God (103K reputation)Forum God (103K reputation)Forum God (103K reputation)Forum God (103K reputation)Forum God (103K reputation)Forum God (103K reputation)Forum God (103K reputation)Forum God (103K reputation)Forum God (103K reputation)

Group: Forum Members
Posts: 548, Visits: 2.6K
Keith, what can I say? I'm the novice here. I only know what I see. What I see is the following:

Sleep = 1     ' Print statement (prints) executes every second.

Sleep = 0.5  ' Print statement (prints) executes every 500mS.

Sleep = 60   ' Print statement (prints) executes every minute.

Wayne's code is simulating the QB SLEEP statement perfectly! I wish I could somehow register "Sleep" with VB and call it like any other VB statement. I'll register it as a Sub though.

Thanks,

Chris

________________________________________________________________ 

"So much to learn. So little time to do it. Wise men know it's later than one thinks"!

Mark's Syntax.Zip    Pause Sub

I don't answer programming questions via PMs. That's what the forum is for! 

Keithuk
Keithuk
Forum God
Forum God (298K reputation)

Group: Moderators
Posts: 1.9K, Visits: 5.5K
CDRIVE (2/5/2007)

Sleep 1                  ' Wait 1 second between each print statement.

Sleep 1 doesn't wait for 1 second not in VB. It will wait for 1 thousandth of a second which you won't notice. Wink

Keith

I've been programming with VB for 17 years. Started with VB4 16bit Pro, VB5 Pro, VB6 Pro/Enterprise and now VB3 Pro. But I'm no expert, I'm still learning.

CDRIVE
CDRIVE
Forum God
Forum God (103K reputation)Forum God (103K reputation)Forum God (103K reputation)Forum God (103K reputation)Forum God (103K reputation)Forum God (103K reputation)Forum God (103K reputation)Forum God (103K reputation)Forum God (103K reputation)

Group: Forum Members
Posts: 548, Visits: 2.6K
Wayne, I took your Sleep Sub and ran with it. Oh yeaaaaaaaaaa! I added a few required things like the Print text1 and defined text1 as a String. When I got it to run I was surprised to see that the print out printed 1, 12, 123, 1234, and so on. It was not exactly what I wanted but I found it interesting. I'm sure I'll find a use for that output format in another project someday. Anyway, I messed with the code a bit more and ended up with the code below. Thank you sooooo much for your time and skill. It works great!!

'_____________________________________________________________________________
'Some of this code provided by Wayne Spangler of a1vbcode.com. He specificaly supplied 'the Private Sub Sleep block which is the heart of the timing sequence.
'_________________________________________________________________________________________

Option Explicit
Dim Display As String
Dim Prompt As String
Dim Counter As Integer
Dim Check As Boolean

Private Sub Command1_Click()
    Do   ' Outer loop.
       Do While Counter < 20        ' Inner loop.
          Counter = Counter + 1     ' Increment Counter.
          Sleep 1                  ' Wait 1 second between each print statement.
          Display = Prompt & Counter   ' Print each count
          Print Display
          If Counter = 10 Then      ' If condition is True.
          Check = False             ' Set value of flag to False.
          Exit Do                   ' Exit inner loop.
          End If
       Loop
    Loop Until Check = False        ' Exit outer loop immediately.
End Sub

'add a delay time to the current time and waits for the current
'time to catch up.
Private Sub Sleep(ByVal delay As Single)
    Dim x As Single
    x = Timer + delay
    Do While x > Timer
        DoEvents
    Loop
End Sub

Private Sub Form_Load()
Show
Prompt = "Count  "                     'Prefix Print Statement with Count.
End Sub


________________________________________________________________ 

"So much to learn. So little time to do it. Wise men know it's later than one thinks"!

Mark's Syntax.Zip    Pause Sub

I don't answer programming questions via PMs. That's what the forum is for! 

waynespangler
waynespangler
Forum God
Forum God (97K reputation)Forum God (97K reputation)Forum God (97K reputation)Forum God (97K reputation)Forum God (97K reputation)Forum God (97K reputation)Forum God (97K reputation)Forum God (97K reputation)Forum God (97K reputation)

Group: Forum Members
Posts: 910, Visits: 5.4K
Try writing your own delay if the sleep is not what you want. Try this:
Option Explicit

Dim counter As Integer
Dim check As Boolean

Private Sub Command1_Click()
    Do   ' Outer loop.
       Do While counter < 20        ' Inner loop.
          counter = counter + 1     ' Increment Counter.
          Sleep 1                   ' Wait 1 second between each print statement.
          'changed your output some
          Text1 = Text1 & counter   ' Print each count
          If counter = 10 Then      ' If condition is True.
          check = False             ' Set value of flag to False.
          Exit Do                   ' Exit inner loop.
          End If
       Loop
    Loop Until check = False        ' Exit outer loop immediately.
End Sub

'add a delay time to the current time and waits for the current
'time to catch up.
Private Sub Sleep(ByVal delay As Single)
    Dim x As Single
    x = Timer + delay
    Do While x > Timer
        DoEvents
    Loop
End Sub

You pass the sleep a single number so if you want it to delay .1 sec you can pass it .1

Hope this helps.

Wayne

I know enough to be dangerious.

It is hard to understand how a cemetery can raise its burial rates and blame it on the cost of living.

Mark
Mark
Forum God
Forum God (142K reputation)

Group: Moderators
Posts: 1.1K, Visits: 11K
See if this does it for you

Option Explicit
Dim i As Integer

Private Sub Form_Load()
    Timer1.Interval = 1000
End Sub

Private Sub Timer1_Timer()
    i = i + 1
    Me.Caption = i
    
    If i = 10 Then
        Timer1.Enabled = False
    End If
End Sub

GO


Similar Topics


Reading This Topic


Login
Existing Account
Email Address:


Password:


Social Logins

Select a Forum....

















A1VBCode Forums


Search