Solved

Pass Variable to Shell VB6

Posted on 2011-03-12
5
862 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 
LVL 86

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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
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…

732 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