Solved

Pass Variable to Shell VB6

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
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…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
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…

867 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

16 Experts available now in Live!

Get 1:1 Help Now