Solved

Restart Application With Variable Intact

Posted on 2004-08-30
9
622 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
Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

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.

 
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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

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

Suggested Solutions

If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
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…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

839 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