r/visualbasic • • 2d 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!

4 Upvotes

13 comments sorted by

12

u/Due-Mortgage-6854 2d ago edited 2d 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 2d ago

Thanks that took care of the problem!!!

2

u/Brilliant_Park_2882 1d 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 1d 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 10h 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 2d ago

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

2

u/Cdream-2018 2d 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 2d ago

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

2

u/Mayayana 2d 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 2d ago

lookup DoEvents ()

1

u/Belasius1975 1d ago

me.sleep

1

u/DaveX64 1d 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