• Passing in Value when Launching EXE (VB6)

    Home » Forums » AskWoody support » Productivity software by function » Visual Basic for Applications » Passing in Value when Launching EXE (VB6)

    Author
    Topic
    #381641

    I developed an application that uses our email system to send text pages through our paging company. I want to leverage this with alerts we get from antoher system that monitors our servers and send the text directly to the pager. The system can do this anyway but I want to use the application I developed so I can query the technical person on call for that night and page them.

    Anyhow, this monitoring application will save the alert text to a file (possibly even to an ODBC database which I have to check). It will also launch an exe of our choice. I would like to be able to launch my paging application but at the same time pass in the text generated by the alert.

    Is this getting into constructors which VB6 doesn’t do real well or is there some other method that would make this possible?

    Viewing 1 reply thread
    Author
    Replies
    • #644277

      Mike,

      VB can take command Line parameters, so you could pass your app the path to the text file, instead of the actual text, and then use your VB app to open and read the text file.

      To use the command line parameter you would call your exe like this:

      c:fullpathtoMyCustomApp.exe /MyCustomParameter

      Then in your startup code you could do something like this:

      If Command = “” then
      ‘There was no command line parameter passed to the exe
      else
      ‘there was a command line parameter passed, so open the text file here
      end if

      • #644284

        Gentlemen, thank you both. This almost seems too easy.

        So there is nothing I need to do within the application itself, other than to look for the Command() ? If so, that is really clean. I am assuming that your examples can also be run from the Sub Main()? This way I wouldn’t even need a user interface.

        • #644286

          Yes it can be run from Sub Main. I have a small VB app that does just that, without a UI when launched with a parameter, but if there is no parameter, the UI opens.

          • #644288

            Thanks Bryan. I like your method, it sounds a lot more versatile.

            Thanks again.

          • #644330

            Bryan, will it accept multiple parameters or do you just parse the one string passed ?

            • #644338

              Mike,

              It is one long string that needs to be parsed.

              If you look at the Command Function example in the On-Line help, there is a function that you pass the entire string to and it will return an array with each “parameter” separated.

              Although it seems like a lot of code when the Split function could work equally well to split the parameter, but then again, I didn’t really look to closely at the code.

            • #644348

              I thought the same thing when I looked at the example and didn’t look closely either. They probably wrote the example before they had split. –Sam

    • #644279

      Mike, you can use the Command function. If you create an app with a single textbox and the following load event, then the command line arguments will appear in the textbox. HTH –Sam

      Option Explicit
      
      Private Sub Form_Load()
          Text1 = Command()
      End Sub
    Viewing 1 reply thread
    Reply To: Passing in Value when Launching EXE (VB6)

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: