Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Trying to reset Visual Basic

Status
Not open for further replies.

Newf69

Technical User
Mar 27, 2003
7
CA
I am using Visual Basic to display a message when a sensor triggers the com port. I have this part done, my problem is when the com port is triggered the program ends. Is there a way to reset the program after a predescribed time period has passed so the process can start all over again.

thank -you
 
Perhaps instead of having the program end after the com port is triggered you could use the Sleep function to have it wait and then reset and wait for another trigger.

To use Sleep you have to first declare the function in a module, like so:

Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)

You can then use the function to make the program suspend for as long as you like, say for 10 minutes:

Sleep(600000)

Hope this helps! I used to rock and roll every night and party every day. Then it was every other day. Now I'm lucky if I can find 30 minutes a week in which to get funky. - Homer Simpson
 
Ok thnnkx but do u know how i can get the program to start over again?? I need to clear an LCD display and start over any help will be greatly appricated i would like to start over after 10 seconds!!!

Thank-you
 
I think you missed the point of the previous answer. There is no need to ever END the program. Display the message, then go back to waiting for a new message.

Or is it that your program is crashing?

[fish] No Dolphins were harmed in the posting of this message... Dolphin Friendly Tuna!
 
OK. There are a few different ways to do this, but I think the easiest is to have another VB app run the app in question with the Shell command. Before the first app runs the com-listening app, have the first app create a dummy file somewhere (just a text file, or something like that). After running the com-listening app, the first app will loop and sleep as long as the dummy file exists, like so:

Dim fso

StartOver: 'Label for for restarting process

Set fso = CreateObject("Scripting.FileSystemObject")

Open "C:\Temp\DummyFile.txt" for Output as #1
Print #1, "DummyFile"
Close #1

Shell ("C:\File\Path\com-listening-app.exe", vbNormalNoFocus)

Do
Sleep(2000) 'suspend this prog (not com-app) for 2 secs.
Loop While fso.FileExists("C:\Temp\DummyFile.txt")

Sleep(10000) 'wait for 10 seconds

GoTo StartOver


After the com-listening app receives its message, but before it ends have it delete the dummy file:

fso.FileDelete("C:\Temp\DummyFile.txt", True)

Thus, the first app will find the file no longer there, exit the Do...While loop, wait 10 seconds and GoTo the StartOver: label to start the whole process over.

However, if this is is too "kloogey" for you, you can try an app I found that demonstrates ways to make a VB app Shell another app, and then wait for that app to finish. You can find the sample at
Good Luck! I used to rock and roll every night and party every day. Then it was every other day. Now I'm lucky if I can find 30 minutes a week in which to get funky. - Homer Simpson
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top