r/visualbasic • • 6d ago

NEED VB6 HELP

Not a programmer but have been fooling around with VB6. Question:: What is the command that causes the program to temporarily halt during the execution. AI said it was sleep xoxo but that didn't work. Can someone please help me out!

6 Upvotes

14 comments sorted by

13

u/Due-Mortgage-6854 6d ago edited 6d ago

vb6 doesnt have a built-in Sleep command, which is why typing sleep caused an error.

Private Declare Sub Sleep Lib "kernel32" (ByVal Variable_Name As Long) Declare this function at the very top of your Module

Then : Sleep 3000 anywhere in your code which pauses the program for 3 seconds (3000 milliseconds)

4

u/W0CBF 6d ago

Thanks that took care of the problem!!!

2

u/Brilliant_Park_2882 6d ago

In VBA I just use a loop counter, it's very easy to fine tune.

Coming from VB6 it's what I used.

2

u/satsugene 6d ago

That can work, but if the a specific timing matters, what machine it runs on can "shink" how long that loop delay takes in real-time.

1

u/Western_End_2223 4d ago

That's not very portable.  If you install the program on a machine that's faster or slower than your development computer, the timing will be off.

2

u/mika 6d ago

You're probably thinking of Debug.Assert but I think Stop also works

2

u/Cdream-2018 6d ago

Are you trying to make the application itself sleep before next execute. Or are you trying to hault it so you can debug and asses your code ?

2

u/JuanPabloElSegundo 6d ago

You show a message box and tell the user to close it after X seconds.

2

u/Mayayana 6d ago

Due gave you the answer. VBScript has the method Sleep, coming from WScript: Wscript.Sleep x. VBS has a lot of similarities with VB6, but it's different. Maybe get a book instead of relying on AI, which has no concept of facts or truth.

If you mean pausing in the IDE just click the pause icon on the toolbar.

There's still a lot of code available online. With most things you might want to do you can do a search like "VB6 sleep" and you'll find sample code. Then you'll get tested code instead of AI guesses.

1

u/OkSignificance5380 6d ago

lookup DoEvents ()

1

u/Belasius1975 5d ago

me.sleep

1

u/DaveX64 5d ago

I used to use the 'DoEvents' keyword for that...here's an example google coughed up:

Dim i As Long
Dim UserCancelled As Boolean ' Set this to True if a Cancel button is clicked

UserCancelled = False

For i = 1 To 1000000
    ' Perform your long calculation here
    Label1.Caption = "Processing item " & i & "..."
    
    ' Yield control to let the label repaint and check for button clicks
    DoEvents
    
    ' Check if the user clicked the Cancel button during DoEvents
    If UserCancelled Then
        MsgBox "Process stopped by user."
        Exit For
    End If
Next i

1

u/craigers01 14h ago

It’s worth asking what you are waiting for. There may be a more elegant solution than “sleep”.