Solved

Pass Variable to Shell VB6

Posted on 2011-03-12
5
838 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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Suggested Solutions

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
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…

759 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now