Solved

Restart Application With Variable Intact

Posted on 2004-08-30
9
619 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
Comment Utility
You can't... however, you can temporarily write it's value to a file or registry...

Darko
0
 
LVL 7

Expert Comment

by:_agj_
Comment Utility
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
Comment Utility
What code would i use for my first instance to pass the value
to the next instance

thanks experts

0
 
LVL 22

Expert Comment

by:DarkoLord
Comment Utility
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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 15

Expert Comment

by:unknown_routine
Comment Utility
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
Comment Utility
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
Comment Utility
I have tried

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

but it says object required , whats wrong ??


0
 
LVL 2

Expert Comment

by:zonaltech
Comment Utility
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
Comment Utility
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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
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 Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
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…

763 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

Need Help in Real-Time?

Connect with top rated Experts

6 Experts available now in Live!

Get 1:1 Help Now