Results 1 to 6 of 6

Thread: passing 2 variables with shell

  1. #1

    Thread Starter
    Lively Member
    Join Date
    May 2010
    Posts
    80

    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

  2. #2
    PowerPoster
    Join Date
    Jul 2006
    Location
    Maldon, Essex. UK
    Posts
    6,334

    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.

  3. #3
    PowerPoster
    Join Date
    Feb 2006
    Posts
    24,482

    Re: passing 2 variables with shell

    Quote Originally Posted by Doogle View Post
    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.
    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

  4. #4

    Thread Starter
    Lively Member
    Join Date
    May 2010
    Posts
    80

    Re: passing 2 variables with shell

    Very nice, thank you very much

  5. #5

    Thread Starter
    Lively Member
    Join Date
    May 2010
    Posts
    80

    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.

  6. #6
    PowerPoster
    Join Date
    Jul 2006
    Location
    Maldon, Essex. UK
    Posts
    6,334

    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
  •  



Click Here to Expand Forum to Full Width