Solved

save variable value for next program boot

Posted on 2002-04-15
7
151 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 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

Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

Question has a verified solution.

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

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
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 Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
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…
Suggested Courses
Course of the Month5 days, 11 hours left to enroll

627 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