• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 154
  • Last Modified:

save variable value for next program boot

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
David777
Asked:
David777
1 Solution
 
ExcelRayCommented:
Hi David777

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

Ray at home
0
 
KarcOriginCommented:
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
 
xSinbadCommented:
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
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!

 
BerCommented:
How about just writing it out to as file..?
0
 
Éric MoreauSenior .Net ConsultantCommented:
ExcelRay is correct. See GetSettings and SaveSettings in the VB help. These are really easy to use.
0
 
olxCommented:
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
 
rspahitzCommented:
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.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now