Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

How to create delay in Visual Basic?

Status
Not open for further replies.

bb

Newbie level 6
Joined
May 17, 2005
Messages
11
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,377
visual basic delay

How to create delay in Visual Basic? thx 4 help..

Private Sub Command1_Click()

dim i as Integer
For i = 1 To 1000
Next i
Picture1.Print 1

End Sub

does the program above create any delay before printing number 1?
 

cfant

Full Member level 3
Joined
Apr 4, 2001
Messages
188
Helped
25
Reputation
50
Reaction score
6
Trophy points
1,298
Location
California, USA
Activity points
1,151
vb delay

Yes, but you will have hard time trying to see it. Using a empy loop is bad way to introduce delay in any program. See this link for better description:

https://support.microsoft.com/kb/q212667/#XSLTH3125121123120121120120

Or use this:

Private Declare Function GetTickCount Lib "kernel32" () As Long

Public Sub SlowDown(MilliSeconds As Long)

Dim lngTickStore As Long

lngTickStore = GetTickCount()

Do While lngTickStore + MilliSeconds > GetTickCount()
DoEvents
Loop

End Sub
 

Cortex

Full Member level 3
Joined
Mar 26, 2005
Messages
182
Helped
12
Reputation
24
Reaction score
4
Trophy points
1,298
Location
Morocco
Activity points
2,733
delay visual basic

Sleep (1000) // pause 1 s
 

jhbbunch

Full Member level 4
Joined
Feb 21, 2006
Messages
199
Helped
17
Reputation
34
Reaction score
3
Trophy points
1,298
Activity points
2,902
delay in vb

I used the Win32 API functions QueryPerformanceCounter() and QueryPerformanceFrequency() to get time intervals as low as 3 microseconds some time ago. I helped a student drive two stepper motors with it with perfect accuracy. But use them in a loop that has DoEvents() as stated above. Also, you can get the odd glitch because of the preemptive nature of a multitasking system when time intervals get quite small.
 

algilsan

Advanced Member level 4
Joined
Jan 20, 2002
Messages
116
Helped
7
Reputation
14
Reaction score
6
Trophy points
1,298
Location
chile
Activity points
1,078
delay in visual basic

Another way to do the same

Public Sub Delay(tiempo As Integer)

salir = False
Timer1.Interval = tiempo
Timer1.Enabled = True
Do While (Not salir)

DoEvents

Loop
Timer1.Enabled = False

End Sub
 

ibrahim03

Full Member level 1
Joined
Sep 29, 2005
Messages
99
Helped
5
Reputation
10
Reaction score
2
Trophy points
1,288
Activity points
2,335
delay en visual basic

I dont know about vb4 but I use vb 6 and it has timers. you just have to add a timer object to your form and set the interval of the timer. In this way you can get a delay from 1ms to abt 3 seconds (depending on the value of the interval). If vb4 has timers then it is fairly easy to create delays !!
 

nav_vlsi

Advanced Member level 4
Joined
Aug 17, 2005
Messages
114
Helped
45
Reputation
90
Reaction score
32
Trophy points
1,308
Location
India
Activity points
2,065
visual basic delay function

timer is a easy way to implement delays in VB
 

AlexOrtega

Newbie level 1
Joined
Mar 29, 2014
Messages
1
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
6
I use this code to calculate very tiny delays

Dim t1, t2, lapse As Double

lapse = 1000000 ' Use a large value or you will get a "divide by 0" error

t1 = Timer
For cont = 1 To lapse
Next
t2 = Timer

Text1 = "Seconds used: " & t2 - t1
Text2 = "In one second the instruction For executes about " & lapse / (t2 - t1) & " times"

As example, in my computer, For is executed about 42,000,000 in one second
 
Last edited:

spudboy488

Full Member level 5
Joined
Oct 10, 2012
Messages
272
Helped
69
Reputation
140
Reaction score
75
Trophy points
1,308
Activity points
3,058
Code:
    Public Sub Wait(ByVal mS As Integer, Optional ByVal CheckEvents As Boolean = False)

        Dim Start As Long = Now.Ticks

        Do
            If CheckEvents Then Application.DoEvents()
        Loop Until Now.Ticks > Start + (mS * TimeSpan.TicksPerMillisecond)

    End Sub
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Top