Solved

save variable value for next program boot

Posted on 2002-04-15
7
147 Views
Last Modified: 2010-05-02
Dear all,
I want to save a variable value as bootup parameter when next time my program boots. How can I do?

any suggestion appreciated
David777
0
Comment
Question by:David777
7 Comments
 
LVL 3

Expert Comment

by:ExcelRay
ID: 6943784
Hi David777

Probably the registry is the best place and most common solution for such things.

Ray at home
0
 
LVL 5

Expert Comment

by:KarcOrigin
ID: 6943826
Hi David777,

In 16-bit Windows-based applications this type of information generally stores in INI (initialization file) but in Win32-based applications you should store initialization information in the registry.

I hope it will help you.

Thanks
0
 
LVL 6

Expert Comment

by:xSinbad
ID: 6943890
Look up savesetting and getsetting in the help. These are used to save to the reg. But they only save into a special section of the reg if you want total control you should look at another function to read/write the reg.


Cheers
Marcus
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 2

Expert Comment

by:Ber
ID: 6944219
How about just writing it out to as file..?
0
 
LVL 69

Expert Comment

by:Éric Moreau
ID: 6944410
ExcelRay is correct. See GetSettings and SaveSettings in the VB help. These are really easy to use.
0
 
LVL 1

Accepted Solution

by:
olx earned 50 total points
ID: 6946069
copy and paste....

'when your app ends, it saves the value in the file
'replace DesiredValue with the variable name you wish

Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)

    Dim V As Long
    Open App.Path & "\" & App.EXEName & ".cfg" For Random As #1 Len = 4
    V = DesiredValue
    Put #1, 1, V
    Close 1
       
End Sub

'when your app starts, it loads the value from the file

Private Sub Form_Load()

    Dim V As Long
    Open App.Path & "\" & App.EXEName & ".cfg" For Random As #1 Len = 4
    Get #1, 1, V
    DesiredValue = V
    Close 1
   
End Sub


and if you like to use more values put this in a module:


type ConfigFile

     Value1 as long
     Value2 as long
     Value3 as long
     Value4 as date
     Value5 as integer
     SomeText as string * 100

end type

'and replace the lines:
'    Dim V As Long
'    Open App.Path & "\" & App.EXEName & ".cfg" For Random 'As #1 Len = 4

'for the lines
'    Dim V as configfile
'    Open App.Path & "\" & App.EXEName & ".cfg" For Random As #1 Len = len(v)

'to retrieve the values query them inside the form_load like this:

'    somevar = v.value1
'    someOtherVar = v.value2

hope this helps.
0
 
LVL 22

Expert Comment

by:rspahitz
ID: 6949363
Here's how we implemented it:

SaveSetting App.CompanyName, App.EXEName, RegistryEntryName, strDataToSave

-and-

strRegInfo = GetSetting(App.CompanyName, App.EXEName, RegistryEntryName, vbNullString)

If strRegInfo = vbNullString Then
  msgbox "not currently in registry"
else
  ' load strRegInfo somewhere to continue where you left off or otherwise restore a setting
end if

--
The above would work well for doing things like restoring the window location and size to wherever the user left it when the app closed.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
VBA saving file message display 5 57
Copy a row 12 59
VBA Shell can't Find Word document 11 77
Macro Excel - Multiple If conditions 2 65
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…
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…
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…
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…

864 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

18 Experts available now in Live!

Get 1:1 Help Now