By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,998 Members | 2,773 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,998 IT Pros & Developers. It's quick & easy.

Wait command in visual basic 2005

P: 2
I have just started learning visual basic 2005. I tried entering the command: Wait(1000) in order for the program to wait for 1 second before proceeding, but it rejected this saying Wait wasn't defined. How do I enter a pause between lines of code? Since I'm very new to visual basic, I would like to be able to follow things along on the screen without them whizzing right by.Thank you!
Sep 7 '07 #1
Share this Question
Share on Google+
4 Replies

P: 8
Expand|Select|Wrap|Line Numbers
  2. System.Threading.Thread.Sleep(1000) will put the machine to sleep for 1 sec.
Sep 7 '07 #2

P: 2
Sorry to bother, but I tried the sleep threading method you provided, and it doesn't work. It also makes it impossible to stop the program without going back to the debug panel and selecting the stop square button.

Here is the code its in. I inserted a single quotation mark to indicate the step following is to implement the wait function, then I tried inserting your bid of code to sleep and set the time for 5000 milliseconds. It doesn't appear to be in the correct location, but as a new person, it seemed a logical point to place it for me. If you have a suggestion, I would sincerely appreciate it. My program was taken off the net and reads a temperature sensor connected to the serial port. The sensor outputs data continuously, and all I do is read it. I just don't need to keep reading it so often - hence the need for a wait / sleep delay between reading and writing to the text box. Thanks for your help!

Private Sub AccessForm(ByVal action As String, ByVal formText As String, ByVal textColor As Color)

Select Case action

' Select an action to perform on the form.
' (Can add more actions as needed.)

Case "AppendToMonitorTextBox"

'implement a wait function


' Append text to the rtbMonitor textbox using the color for received data.

rtbMonitor.SelectionColor = colorReceive

'Return to the default color.

rtbMonitor.SelectionColor = colorTransmit

' Trim the textbox's contents if needed.

If rtbMonitor.TextLength > maximumTextBoxLength Then


End If

Case "DisplayStatus"

' Add text to the rtbStatus textbox using the specified color.

DisplayStatus(formText, textColor)

Case "DisplayCurrentSettings"

' Display the current port settings in the ToolStripStatusLabel.


Case Else

End Select

End Sub
Sep 7 '07 #3

P: 63
This is what I use, and always works fine for me

Expand|Select|Wrap|Line Numbers
  1.     Public Sub Wait(ByVal Milliseconds As Integer)
  2.         Dim time As Date
  3.         time = Now.AddMilliseconds(Milliseconds)
  4.         Do While time > Now
  5.             Application.DoEvents()
  6.         Loop
  7.     End Sub
Sep 7 '07 #4

P: n/a
Awesome! Dude you awesome this great!!
Sep 29 '10 #5

Post your reply

Sign in to post your reply or Sign up for a free account.