Connecting Tech Pros Worldwide Forums | Help | Site Map

Code to Save a Form before closing

Member
 
Join Date: Sep 2007
Location: Virginia Beach, VA
Posts: 57
#1: 3 Weeks Ago
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:

Expand|Select|Wrap|Line Numbers
  1. Private Sub Command2_Click()
  2. Form2.Text1.Text = "C:\Results\Report-NBC1.xls"
  3. ‘Is there a line of code here that would save Form2 before the GUI is closed in the next line?
  4. Unload Form1
  5. Shell ("C: \NBC1.exe")  ‘This is the Perl executable that will reopen the VB GUI when complete
  6. 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
best answer - posted by vb5prgrmr
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

Dököll's Avatar
Moderator
 
Join Date: Nov 2006
Location: Upstate NY - US
Posts: 2,268
#2: 2 Weeks Ago

re: Code to Save a Form before closing


Are you getting any errors, Terra, with the bit of code posted?
Member
 
Join Date: Sep 2007
Location: Virginia Beach, VA
Posts: 57
#3: 2 Weeks Ago

re: Code to Save a Form before closing


No i'm not getting any errors.
Newbie
 
Join Date: Oct 2009
Posts: 28
#4: 2 Weeks Ago

re: Code to Save a Form before closing


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
Member
 
Join Date: Sep 2007
Location: Virginia Beach, VA
Posts: 57
#5: 2 Weeks Ago

re: Code to Save a Form before closing


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