-
Jan 29th, 2011, 05:03 AM
#1
Thread Starter
Lively Member
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
-
Jan 29th, 2011, 05:26 AM
#2
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.
Last edited by Doogle; Jan 29th, 2011 at 07:17 AM.
-
Jan 29th, 2011, 11:38 AM
#3
Re: passing 2 variables with shell
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
-
Jan 29th, 2011, 11:13 PM
#4
Thread Starter
Lively Member
Re: passing 2 variables with shell
Very nice, thank you very much
-
Jan 30th, 2011, 07:16 PM
#5
Thread Starter
Lively Member
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.
-
Jan 31st, 2011, 01:24 AM
#6
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, ",")
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|