Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

save variable value for next program boot

Posted on 2002-04-15
7
Medium Priority
?
153 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 2

Expert Comment

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

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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
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…
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…
Suggested Courses

963 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