Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Storing variables after exit

Status
Not open for further replies.

DickiePotter

Programmer
Jan 8, 2001
30
0
0
GB
Hi,
How can variables be store for use when an application is reopened anfer being closed?
My only ideas so far involve ini's and the registry but I have no idea about how to use either.
Please help me!!!
 
Search for SaveSetting and GetSetting in VB help.
VCA.gif

Alt255@Vorpalcom.Intranets.com
 
Warning,savesetting saves to CURRENT_USER, so a different user gets different settings. You need to save to LOCAL_MACHINE on a multi-user system

There is a nice example on
 
Sorry, I thought Dickie was trying to communicate between between two apps in the current session. I didn't think he wanted to make permanent changes in the registry.
VCA.gif

Alt255@Vorpalcom.Intranets.com
 
Hi,
ini files are basically text files with a ".ini" extension. So you could use the the "write #" command to output data to the ini file and the "input #" command to input data from it. I hope this helps!
Brett Please visit my websites!
 
there are some very easy api's for inifiles,
once you get the hang of it, it is easier than print#
 
Thankx everyone, I've decided to use an INI as a text file and i'm slowly working out how to put it all together
Thankx again
 
Code:
Private Declare Function GetPrivateProfileString Lib "kernel32" Alias "GetPrivateProfileStringA" (ByVal lpApplicationName As String, ByVal lpKeyName As Any, ByVal lpDefault As String, ByVal lpReturnedString As String, ByVal nSize As Long, ByVal lpFileName As String) As Long
Private Declare Function WritePrivateProfileString Lib "kernel32" Alias "WritePrivateProfileStringA" (ByVal lpApplicationName As String, ByVal lpKeyName As Any, ByVal lpString As Any, ByVal lpFileName As String) As Long
Private Sub Form_Load()
    'KPD-Team 1999
    'URL: [URL unfurl="true"]http://www.allapi.net/[/URL]
    'E-Mail: KPDTeam@Allapi.net
    Dim Ret As String, NC As Long
    'Write the setting to the file (c:\test.ini) under
    '   Project1 -> Keyname
    WritePrivateProfileString App.Title, "KeyName", "This is the value", "c:\test.ini"
    'Create a buffer
    Ret = String(255, 0)
    'Retrieve the string
    NC = GetPrivateProfileString(App.Title, "KeyName", "Default", Ret, 255, "C:\test.ini")
    'NC is the number of characters copied to the buffer
    If NC <> 0 Then Ret = Left$(Ret, NC)
    'Show our string
    MsgBox Ret
    'Delete the file
    Kill &quot;c:\test.ini&quot;
End Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top