Problems executing command
Hi there,
I'm pretty new to VB6 and used to work with Access VBA, so please bear with me.
At the moment I'm trying to have VB execute a command with some command line parameters. One of these parameters is taken from a textbox. For some reason the correct command is displayed in a msgbox, but when I try to have VB execute it, it doesn't do this correctly.
This is my code:
Code:
Private Sub username_LostFocus()
Dim sYourCommand As String
sYourcommand0 = "C:\iris\encrypt.exe "
sYourCommand1 = username
sYourCommand2 = " > c:\iris\pwoutput1.txt"
MsgBox (sYourcommand0 & sYourCommand1 & sYourCommand2)
Dim retval As Double
retval = Shell(sYourcommand0 & sYourCommand1 & sYourCommand2, vbNormalFocus)
End Sub
It seems that only sYourcommand0 is being executed and the rest is left behind. However as mentioned the messagebox does display the correct command while it seems to me that both should display identical.
Any suggestions on how I can have VB execute this command are welcome.
Also, in Access I used the AfterUpdate to perform an action once a textbox was updated, I cannot get this to work in VB6 and therefore used LostFocus. Would anyone have a solution for this?
Kind regards,
Ronald.
Re: Problems executing command
the reason i suspect is the operation ceases after the execution of the first command. i think you can use the api waitforsingleobject to wait untill all the command is properly executed, or on the easy way
you can try by creating a batch file and then executing with the shell command
HTH
Re: Problems executing command
Thanks for your reply. In fact all 3 commands combined are one command. The first part is the executables. The 2nd and 3rd are the parameters to the executables.
I would prefer not to use a batch file as the 2nd part of the command changed depending on what is entered into a textbox.
I anyone could give me an example on how to execute a shell command with some parameters behind of which one is not static:
Code:
C:\iris\encrypt.exe username > c:\iris\pwoutput1.txt
Above is the command I need executed where username is the input taken from a textfield called username.
Cheers,
Ronald.
Re: Problems executing command
Welcome to VBForums :wave:
I'm not sure why you are using 3 separate variables (none of which are declared) rather than just one. Also the retval variable is pointless, as you don't actually use it after setting it.
It would be better to write the code like this:
Code:
Private Sub username_LostFocus()
Dim sYourCommand As String
sYourCommand = "C:\iris\encrypt.exe " & username & " > c:\iris\pwoutput1.txt"
MsgBox sYourCommand
Shell sYourCommand, vbNormalFocus
End Sub
I doubt these changes will have any effect, but they make it easier to read and check.
I suspect the issue is not related to your code as such, but to the command line you are using - I think you would get the same behaviour if you ran the same thing at a command prompt (in the same folder as your program).
That may be due to the space after > , or it may be because the executable needs you to put the parameters inside quotes, or it may be because you haven't provided enough information (I don't know what username signifies, but if it is a filename you need the full path to the file).
Re: Problems executing command
if any of the paths or username could have a space, it must be enclosed in quotes