Restart Application With Variable Intact

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.

Jimmyx1000Asked:
Who is Participating?

Improve company productivity with a Business Account.Sign Up

x
 
JR2003Connect With a Mentor Commented:
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
 
DarkoLordCommented:
You can't... however, you can temporarily write it's value to a file or registry...

Darko
0
 
_agj_Commented:
or.....u can call your vb application with parameters....

the previous instance can pass the value to the next instance before dying off ;)
0
Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

 
Jimmyx1000Author Commented:
What code would i use for my first instance to pass the value
to the next instance

thanks experts

0
 
DarkoLordCommented:
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
 
unknown_routineCommented:
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
 
unknown_routineCommented:
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
 
Jimmyx1000Author Commented:
I have tried

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

but it says object required , whats wrong ??


0
 
zonaltechCommented:
Use App.ExeName (returns the app's <whatever>.EXE name), instead of Variable.exe (VB doesn't know what variable.exe means)
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.