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!

running a dos program through vb

Status
Not open for further replies.

metalman

Programmer
Sep 17, 2001
35
US
i have a excell application that i have aded a button into to pull in data from a db. i want to create another button to run several dos commads. how would i get vba to run these 30 comand lines on the button click.
 
use VB shell command. Open up a vb form and type in the word shell. Highlight the word and hit F1. This should bring you to the help page(if MS Visual Studio help page is installed).
 
often, if you have a bunch of DOS commands to execute, it is better to make a batch file and have the shell execute this. One thing that this lets you do is pipe the output to a file and then you can read that file back into vb and display it.
 
Extra Note on using the shell command is after executing the shell command VB continues to execute statements so doesn't wait to see if the shell process finished or not.
If you need to wait for the process to finish then two options are to have a do loop which just keeps looping until a condition is met, creation of a file for example.

The other method is to use API calls, these are noted in the API forum somewhere can't remember of the top of my head what the calls are. Be aware though that different platforms dont all have the same API calls.
 
To address martyau's thoughts on an API method just do a keyword search in this forum for ShellAndWait. You should find several variants on a theme.
 
thanks all got it going cant believe i didnt think of a batch file.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top