Pass Variable to Shell VB6

I want to pass two variables from my EXE to be received and used by another EXE that I Shell to.

I have tried ..
Dim pstrMessage as String
Dim pstrEmail as String
pstrMessage  = "Hello World"
pstrEmail = ""
Shell (App.Path & "\CCEmailer.exe pstrMessage pstrEmail")

and in the receiving EXE that is opened by the Shell command
Dim args as string
args = Command()
msgbox args
Unload Me

All I am receiving in the message box is
pstrMessage pstrEmail

I am not getting "Hello World or"

Who is Participating?
Mike TomlinsonConnect With a Mentor Middle School Assistant TeacherCommented:
Change your line to:

    Shell App.Path & "\CCEmailer.exe " & pstrMessage & " " & pstrEmail
Whith the exception of setting up some sort of communication between two programs, the only way you can "pass" variables to a program via the Shell command is to include the variables on the command line in such a way that the program you're trying to call will understand.  Within a VB program, you can use Command$ to access variables passed on the command line.
Chris Raisin(Retired Analyst/Programmer)Commented:
'This test sample code is for a program called "Test.exe"
'We are assuming the program can accept up to two parameters
Private Sub Main()

dim strCommand() as string   'an array to hold each parameter
dim intToken as integer      'a loop counter used when examining each

'"Command" is an internal function which returns the values
'(as a single string value) of all values added after the
' programs "executable" name on the command line.
'(i.e after the "Test.exe")

strCommand = split(Command," ") 'assuming a space delimiter between
                              'parameters but this could be "commas"
                              'in which case it would be coded as:
                              ' cCommand = split(command,",")
if uBound(strCommand) < 1 then
  MsgBox "Syntax: TEST <firstparam> <seconparam>"
  for intToken = 0 to UBound(strCommand)
    select case intToken
      case 0    'the first parameter is tested here
                'since this is a zero based array  
         'do something
      case 1    'the second parameter is tested here  
         'do something
      case else
         'no code here - do nothing for excess parameters not needed
         'or perhaps display error message showing correct order or
         'number of parameters
    end select
  ' Now more code follows...........
end sub  

Chris Raisin(Retired Analyst/Programmer)Commented:
The previous was just an example for interest sake.

The quick solution to your problem is to change the shell command to:
(as Idle Mind pointed out)

    Shell App.Path & "\CCEmailer.exe " & pstrMessage & " " & pstrEmail

and then your message box line could be:

   MsgBox Command(0)+ " " +Command(1)  ' or even just "MsgBox Command"  !!

kalbarrimanAuthor Commented:
Thank you. Perfect
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.