Solved

Pass Variable to Shell VB6

Posted on 2011-03-12
5
855 Views
Last Modified: 2012-05-11
Hi
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 = "test@myemail.com"
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 Test@myemail.com"

Thanks
0
Comment
Question by:kalbarriman
5 Comments
 
LVL 85

Accepted Solution

by:
Mike Tomlinson earned 500 total points
ID: 35119715
Change your line to:

    Shell App.Path & "\CCEmailer.exe " & pstrMessage & " " & pstrEmail
0
 
LVL 16

Expert Comment

by:HooKooDooKu
ID: 35119718
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.
0
 
LVL 13

Expert Comment

by:Chris Raisin
ID: 35120746
'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
                             'parameter

'"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>"
else
  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
  next
  ' Now more code follows...........
endif
end sub  

next
 
0
 
LVL 13

Expert Comment

by:Chris Raisin
ID: 35120776
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"  !!





0
 

Author Closing Comment

by:kalbarriman
ID: 35123142
Thank you. Perfect
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

685 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question