passing 2 variables with shell
I need to pass 2 variables in a shell command that opens another program I have written. I have successfly passed one variable but can't seem to get two to get thru. Here is my code.
******* In sending program ******
Private Sub Command3_Click()
Dim strDBPath As String
Dim strmail As String
strDBPath = Layout.Text67.Text
strmail = Text17.Text
Shell "C:\Program Files\Denali\Page Print.exe " & strDBPath & " " & strmail
End Sub
****** In receiving program *******
Private Sub Form_Load()
Dim strDBPath As String
Dim strmail As String
strDBPath = Command
Text68.Text = strDBPath
strmail = Command
Text34.Text = strmail
Printlayout.WindowState = 0
End Sub
Thank you for your help
Re: passing 2 variables with shell
The Command function returns all the arguments in one go, so in your case you'll have to split it on the space character to isolate each one.
eg
Code:
Private Sub Form_Load()
Dim strDBPath As String
Dim strmail As String
Dim strArgs() As String
strArgs = Split(Command, " ")
If UBound(strArgs) >= 2 Then
Text68.Text = strArgs(0)
Text34.Text = strArgs(1)
Printlayout.WindowState = 0
Else
MsgBox "Insufficient Arguments", , "Initialise"
End If
End Sub
EDIT: You may wish to review the Shell Function documentation (http://msdn.microsoft.com/en-us/libr...(v=VS.60).aspx) especially the Remarks section regarding security.
Re: passing 2 variables with shell
Quote:
Originally Posted by
Doogle
Agreed.
To be explicit the full path of the program being run needs to be quoted:
Shell """C:\Program Files\Denali\Page Print.exe"" " & strDBPath & " " & strmail
Re: passing 2 variables with shell
Very nice, thank you very much
Re: passing 2 variables with shell
Ok sorry to say when I used this it didn't work. It wants to split the first variable into two different ones instead of sending 2 separate variables. I tried changing things around a bit and it just kept giving errors.
Re: passing 2 variables with shell
That would indicate the first Argument contains a space character. Simplest way might be to change the delimiter when calling to a value that will never appear in either Argument, eg a comma
Code:
Shell "C:\Program Files\Denali\Page Print.exe " & strDBPath & "," & strmail
and in the \print.exe
Code:
strArgs = Split(Command, ",")