?
Solved

Restart Application With Variable Intact

Posted on 2004-08-30
9
Medium Priority
?
634 Views
Last Modified: 2008-01-09
Id Like to Restart my VB6 application with a variable intact


how can i do a

unload form
keep hold of my (myvariable)
restart my vb6 application

Thanks experts.

0
Comment
Question by:Jimmyx1000
  • 2
  • 2
  • 2
  • +3
9 Comments
 
LVL 22

Expert Comment

by:DarkoLord
ID: 11930615
You can't... however, you can temporarily write it's value to a file or registry...

Darko
0
 
LVL 7

Expert Comment

by:_agj_
ID: 11930654
or.....u can call your vb application with parameters....

the previous instance can pass the value to the next instance before dying off ;)
0
 

Author Comment

by:Jimmyx1000
ID: 11930787
What code would i use for my first instance to pass the value
to the next instance

thanks experts

0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 22

Expert Comment

by:DarkoLord
ID: 11930844
something like this:

use this before restarting:
    Shell App.Path & "\" & App.ExeName & " " & varValue

and this in the main form's code:
   Sub Form_Load()
      your_variable = Command
   End Sub

Darko
0
 
LVL 15

Expert Comment

by:unknown_routine
ID: 11931941
The best way to do this is to write your variable somewhere.

One way is registry, Another way is to write it to an ini file.

for example MyApplication.ini

MyApplication.ini os just a  simple text file.

So whenever your application start  it reads that variable value from the ini file

and when it ends it writes the value of the variable back to the ini file.


Example:

read the variable

open app.apth & "myapplication.ini" for input as #1

dim myVar

input #1, Myvar

close #1

'''''''''''''''''''''''''''''
yourapplication ends,
write  the variable back to the file

open app.apth & "myapplication.ini" for output as #1

dim myVar

print #1, Myvar

close #1



This is a simple but very robust method to handle this situatuion.

















0
 
LVL 15

Expert Comment

by:unknown_routine
ID: 11931967
a little typo was there:

it is app.path


open app.path & "myapplication.ini" for input as #1

dim myVar

input #1, Myvar

close #1

'''''''''''''''''''''''''''''
yourapplication ends,
write  the variable back to the file

open app.path & "myapplication.ini" for output as #1

dim myVar

print #1, Myvar

close #1

0
 

Author Comment

by:Jimmyx1000
ID: 11933609
I have tried

Shell App.Path & "\" & Variable.exe & " " & your_variable

but it says object required , whats wrong ??


0
 
LVL 2

Expert Comment

by:zonaltech
ID: 11935886
Use App.ExeName (returns the app's <whatever>.EXE name), instead of Variable.exe (VB doesn't know what variable.exe means)
0
 
LVL 18

Accepted Solution

by:
JR2003 earned 2000 total points
ID: 11936662
The standard way to do this is to save it to the registry on the unload event and restore it on the load event.
To do this you just need to use the SaveSetting and GetSetting commands.

e.g.

Private MyVariable as String

Private Sub Form_Load()

        MyVariable = GetSetting(App.Title, Me.Name, "MyVariable", "")

End Sub

Private Sub Form_Unload(Cancel As Integer)

    SaveSetting App.Title, Me.Name, "MyVariable", MyVariable

End Sub

The above code would initialise the variable to an empty string on the first time in. From then on it would restore the previous value.

JR
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses

749 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question