Results 1 to 9 of 9

Thread: pass variable from one exe to another

  1. #1

    Thread Starter
    Lively Member
    Join Date
    May 2010
    Posts
    80

    pass variable from one exe to another

    I need to pass a variable from one stand alone program to another. How do I set up a command line for this. i have written both of these programs so there isn't anything already built in to accept the variable.

  2. #2
    Next Of Kin baja_yu's Avatar
    Join Date
    Aug 2002
    Location
    /dev/root
    Posts
    5,989

    Re: pass variable from one exe to another

    Quote Originally Posted by Honsolo View Post
    i have written both of these programs so there isn't anything already built in to accept the variable.
    If that's the case why not modify the sources to handle this?

    What is the state of the applications when you need to pass data from one to another? Are they both running or will the sender app Shell the receiver app when it needs to send?

    If it's the second, you can simply pass the data as command line parameters and in the receiver app grab it using the Command function. If both are running then you have several methods, like using shared files, named pipes, even maybe SendMessage API. It really depends a lot on circumstances and what data is to be transfered.

  3. #3
    PowerPoster Spoo's Avatar
    Join Date
    Nov 2008
    Location
    Right Coast
    Posts
    2,656

    Re: pass variable from one exe to another

    Hon

    In addition to Baja's ideas, there is always the quick and dirty
    text file route.... App1 writes a text file, App2 reads it.

    Spoo

  4. #4
    PowerPoster
    Join Date
    Feb 2006
    Posts
    24,482

    Re: pass variable from one exe to another

    If it does the job using the command line is the best bet.

    For ongoing communication there are many answers. In addition to those mentioned there are also DDE and Mailslots.

    I just happen to have a fresh Mailslots demo on hand. See the notes.txt in the archive. There is a "main" Client program and two Server "sub" programs.
    Attached Files Attached Files

  5. #5

    Thread Starter
    Lively Member
    Join Date
    May 2010
    Posts
    80

    Re: pass variable from one exe to another

    Thank you for the replies

    The first program that needs to pass the variable, will already be running. It needs to pass the path to the database to the second program, that will be shelled by the first program. Can you either point me in the direction to get code or send me something. I have never seen this before.

  6. #6
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,929

    Re: pass variable from one exe to another

    Assuming the path is stored in a variable called strDBPath, and the other program is "c:\program.exe", you can do it like this:

    Code:
    'First program
    Shell "c:\program.exe " & strDBPath
    Code:
    'Second program
    strDBPath = Command
    For more information, see the article How can I use command line parameters in my program? from our Classic VB FAQs (in the FAQ forum)

  7. #7

    Thread Starter
    Lively Member
    Join Date
    May 2010
    Posts
    80

    Re: pass variable from one exe to another

    I know you have me going in the right direction but I seem to keep going down the wrong trail. nothing I have read tells me how to pass a variable in a shell command, only command line passing. It looks like the requirements are different.

    With this:

    Dim strDBPath As String
    strDBPath = "You did it"
    Shell "E:\Dexter\Print Page\Project1.exe" & strDBPath

    I get a file not found error

    With this:

    Dim strDBPath As String
    strDBPath = "You did it"
    Shell "E:\Dexter\Print Page\Project1.exe & strDBPath"

    It opens the Project1.exe and puts "strDBPath" in the text box i have to capture the variable.


    This is what i have in the form load of Project1.exe:

    Dim strDBPath As String
    strDBPath = Command
    Text68.Text = strDBPath

    i know I'm close.

  8. #8
    Next Of Kin baja_yu's Avatar
    Join Date
    Aug 2002
    Location
    /dev/root
    Posts
    5,989

    Re: pass variable from one exe to another

    Shell "E:\Dexter\Print Page\Project1.exe" & " " & strDBPath

  9. #9

    Thread Starter
    Lively Member
    Join Date
    May 2010
    Posts
    80

    Re: pass variable from one exe to another

    Ya DUDE, you da man. That did it. Thank you much

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width