Solved

Restart Application With Variable Intact

Posted on 2004-08-30
9
626 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

 
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 500 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

Independent Software Vendors: 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!

Question has a verified solution.

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

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

717 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