Code to Save a Form before closing

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Perl Beginner
    New Member
    • Sep 2007
    • 57

    Code to Save a Form before closing

    Hello,
    I have written a VB program (VB 6.0) that is basically a GUI for the user to select from various buttons to run other executable files (which I wrote in Perl). When the Perl executable is complete it writes the results to MS Excel. So back to the VB GUI, I have a second form (Form2) where the user can go and select one of the excel reports and open it to view.

    I’ve written the code in VB so that when the user initially clicks the button to run the Perl executable, the location of the excel report will be put in the text box in Form 2.

    Here’s my problem, after the button is selected to run the Perl executable, the VB GUI (which is Form 1) is closed (unloaded) and when the Perl executable is complete, it reopens the VB GUI. So I need a way to save the text of the location of the excel report that was placed in the text box in Form 2 and be there whenever the GUI is reopened.

    Here is a snippet of my code in Form1:

    Code:
    Private Sub Command2_Click()
    Form2.Text1.Text = "C:\Results\Report-NBC1.xls"
    ‘Is there a line of code here that would save Form2 before the GUI is closed in the next line?
    Unload Form1
    Shell ("C: \NBC1.exe")  ‘This is the Perl executable that will reopen the VB GUI when complete
    End Sub
    As i was researching this, i kept reading about using a database, but i don't think that applies here...not sure.

    I hope this is clear. Please let me know if I can give any more information.

    Thanks,
    Terra
  • Dököll
    Recognized Expert Top Contributor
    • Nov 2006
    • 2379

    #2
    Are you getting any errors, Terra, with the bit of code posted?

    Comment

    • Perl Beginner
      New Member
      • Sep 2007
      • 57

      #3
      No i'm not getting any errors.

      Comment

      • vb5prgrmr
        Recognized Expert Contributor
        • Oct 2009
        • 305

        #4
        So let me get this right...

        You shell out another program (written in perl) which does something and puts its results into an excel file (.xls or .csv?) and then you close your program. When the perl program is done, it shells out your vb program? Is this right?

        Okay, so can the perl program pass command line parameters? If so, then all you need to do is test the command object when you startup and if it has a value then load form2, pass it the command line (the path to the file) and show form2. Else if it does not have a command then show form1.

        However, if you do not want to go through the process of changing the perl program to pass a command line parameter to your vb program you could always check for a text file. So your program would do something like this...

        psuedo code
        write text file of path to excel file
        shell other program
        Unload (Do not use end, end very, very bad)

        When program restarts...
        Look for text file
        If found open, read, close, delete, show form2
        else show form1

        If you need help on reading and writing text file from VB then please look up in help the following...

        FreeFile Function
        Open Statement
        Input Function
        Line Input Function
        Close Statement

        Print Statement



        Good Luck

        Comment

        • Perl Beginner
          New Member
          • Sep 2007
          • 57

          #5
          Thanks vb5prgrmr, i will give the text file a try and post my code if i get it working.

          Comment

          Working...