473,395 Members | 1,639 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

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:

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
Nov 5 '09 #1

✓ answered 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

4 3563
Dököll
2,364 Expert 2GB
Are you getting any errors, Terra, with the bit of code posted?
Nov 9 '09 #2
No i'm not getting any errors.
Nov 9 '09 #3
vb5prgrmr
305 Expert 100+
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
Nov 9 '09 #4
Thanks vb5prgrmr, i will give the text file a try and post my code if i get it working.
Nov 9 '09 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

53
by: Cardman | last post by:
Greetings, I am trying to solve a problem that has been inflicting my self created Order Forms for a long time, where the problem is that as I cannot reproduce this error myself, then it is...
1
by: Privacy Trap | last post by:
Hi, As a test to help a friend find out where some code was malfunctioning I wrote the code below for a very simple form with an 'update' chekcing routine... The problem is that I get 1 of 2...
1
by: DFS | last post by:
I'm using a query as the SourceObject for a subform. When I change any of the column widths and try to close the form I'm prompted to save changes to the layout. Anyone know how to suppress...
1
by: **Developer** | last post by:
When I get a closing event in a MID Child form I don't know if the child form is closing or the main form is closing. Is there a way to tell? Thank
12
by: Daniel Walzenbach | last post by:
Hi, I have a Website which allows users to input data. After they finished entering data they can click a button to save their input. Problem now is, that I have no possibility to visualize that...
4
by: Amalorpavanathan Y \(Amal\) | last post by:
Hi All, In Winform Application, MDI form is having Save button. When i close the application, it will ask Save Changes? YES or NO or CANCEL. after i select CANCEL button, i have set e.Cancel =...
6
by: tlyczko | last post by:
I have a BeforeUpdate where I need to ensure that no matter what, the first four fields on the form (one text box, 3 combo box lists) have data entered in them before the user closes the form or...
5
by: David McCallum | last post by:
The object of the code snippet below is to save and restore a form's size and location. The saveFormSettings() method is called when a form is closing and restoreFormSettings() is called after...
8
by: csharpula csharp | last post by:
Hello, I am developing an application which gui is very rich with controls. My question is what is the best way to implement on c# a save require mechanism? I mean to check before closing the...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.