saving setting problem

nn2000
04-17-2003, 03:46 PM
here is a program for multi users log in
the program has the Common Dialog control to let user set the font name,size and background.
how can I let the program save the last setting of the user,like the font name,size ,and anything else they set?

YuanHao
04-17-2003, 04:00 PM
Use the Windows Registry, that would probably be better for your application.

SaveSetting
GetSetting

:D

Digby
04-18-2003, 04:26 AM
here is a program for multi users log in
the program has the Common Dialog control to let user set the font name,size and background.
how can I let the program save the last setting of the user,like the font name,size ,and anything else they set?

You could use the SaveSetting and GetSetting functions, but if you want to save each user's settings individually, try:

'------------------------------------------------------------------
Public Function ReadRegistry(KeyPath As String, KeyName, Optional _
default)
Dim WshShell As Object
On Error Resume Next
Set WshShell = CreateObject("WScript.Shell")
ReadRegistry = WshShell.RegRead(KeyPath & "\" & KeyName)
Set WshShell = Nothing
If IsEmpty(ReadRegistry) Then
If Not IsMissing(default) Then ReadRegistry = default
End If
End Function

Public Function WriteRegistry(KeyPath As String, KeyName, Value)
Dim WshShell As Object
If IsMissing(Value) Then Exit Function
Set WshShell = CreateObject("WScript.Shell")
WshShell.RegWrite KeyPath & "\" & KeyName, Value, "REG_SZ"
Set WshShell = Nothing
End Function

Function DeleteRegistry(KeyPath As String)
Dim WshShell As Object
On Error Resume Next
Set WshShell = CreateObject("WScript.Shell")
DeleteRegistry = WshShell.Regdelete(KeyPath)
Set WshShell = Nothing
If IsEmpty(DeleteRegistry) Then
DeleteRegistry = vbError
End If
End Function
'------------------------------------------------------------------

...and set KeyPath to something like HKEY_CURRENT_USER\Software\MyApp

eg:
Function SaveAndRestore(FontName as String)

writeregistry _
"HKEY_CURRENT_USER\Software\MyApp","font",FontName

FontName=readregistry("HKEY_CURRENT_USER\Software\MyApp","font")

End Function

Just be careful with the KeyPath value. You don't want to accidentally obliterate "HKEY_CURRENT_USER/"

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum