dpopbes
03-08-2003, 02:47 PM
Hi all-I'm a noob so be nice! At work I have this command I have to issue (a lot) to label tapes in our ATL. I wanted to build a little app that will take the slot number I enter into a text box, and the pool ID selected from a pulldown menu and (these are the only parts of the command that change) and have it open a DOS prompt window and execute the command. I'm a little lost on how to do this. Any help would make my day!!
Thanks in advance...
Gamer X
03-08-2003, 02:55 PM
Use the Shell command. Example:
Shell "c:\program argument1 argument2"
Arigato,
Gamer X
dpopbes
03-08-2003, 02:58 PM
Thanks-will this open up a dos prompt window?
SnakeChomp
03-08-2003, 02:58 PM
Use the Shell command. Example:
Shell "c:\program argument1 argument2"
Actually I don't think you want quotes around the entire statement as it will execute the command as a string without substituting in variable amounts. Try this:
Shell "c:\path\to\program " & argument1 & " " & argument2
Now if argument1 and 2 both equal 5, it will make a shell command that looks like this "c:\path\to\program 5 5" instead of "c:\path\to\program argument1 argument2"
dpopbes
03-08-2003, 03:00 PM
Actually I don't think you want quotes around the entire statement as it will execute the command as a string without substituting in variable amounts. Try this:
Shell "c:\path\to\program " & argument1 & " " & argument2
Now if argument1 and 2 both equal 5, it will make a shell command that looks like this "c:\path\to\program 5 5" instead of "c:\path\to\program argument1 argument2"
Right on, you guys are great. Thanks.
dpopbes
03-08-2003, 03:17 PM
I tried to start out with something really simple. I made a form, put a button on it-on the button click I put this-
Private Sub Doit_Click()
Shell "copy D:\jcl.txt C:\jcl.txt"
End Sub
I just wanted to see if I could do something simple like execute a copy command. No dice. Let's start really simple, how do I pull this off?
dpopbes
03-08-2003, 03:44 PM
I've managed to execute CMD.exe using the shell function. Now I need to figure out how to get a command (using input from a text box) on the command line and execute it. Any help is much appreciated!
Thinker
03-08-2003, 04:52 PM
You can't execute commands that are part of the command interpreter
(cmd.exe) using Shell. That is why VB has built-in functions for these
types of commands. For instance, FileCopy for copy and Kill for Del.
You could handle it by creating a .Bat file that runs all the needed
commands and then using Shell to run the .Bat, or you could do all the
commands mixing VB functions with Shell commands, or you could use
the VB Shell command with cmd.exe to execute these other commands.
dpopbes
03-08-2003, 04:56 PM
You can't execute commands that are part of the command interpreter
(cmd.exe) using Shell. That is why VB has built-in functions for these
types of commands. For instance, FileCopy for copy and Kill for Del.
You could handle it by creating a .Bat file that runs all the needed
commands and then using Shell to run the .Bat, or you could do all the
commands mixing VB functions with Shell commands, or you could use
the VB Shell command with cmd.exe to execute these other commands.
How could I create a bat file with the info from my text boxes? I suppose I could create the .bat file then execute it... Sounds could. Now I just need to know how to create the bat file with the info from my text boxes!
SnakeChomp
03-08-2003, 05:03 PM
Edited to not make my post 500 miles wide
How could I create a bat file with the info from my text boxes? I suppose I could create the .bat file then execute it... Sounds could. Now I just need to know how to create the bat file with the info from my text boxes!
Public Sub CreateBatFile(ByVal BatFileName as String, ByVal CommandPath as String, _
ByVal Argument1 as String, ByVal Argument2 as String)
dim iFileNumber as Integer
'get a free file identifier from windows
iFileNumber=FreeFile
'open / create the .bat file
Open App.Path & "\" & BatFileName For Write As #iFileNumber
'write the command line to the file
Print #iFileNumber, CommandPath & " " & Argument1 & " " & Agrument2
'If the arguments need to have /'s in front of them, change the & " " & to & " /" &
'close the file
Close #iFileNumber
End Sub
That should save a batch file with your command line and arguments.
Thinker
03-08-2003, 05:08 PM
To use cmd.exe it would be like...
Shell "cmd.exe /c Dir *.txt", vbHide
or
Shell "cmd.exe /k Dir *.txt", vbNormalFocus
To create the bat file it would be like...
Open "mybatch.bat" For Output As #1
Print #1, "Dir *.txt"
Close #1
Shell "mybatch.bat"