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!

passing controls to functions for saving in registry

Status
Not open for further replies.

MickTheBelgian

Programmer
Jan 11, 2001
160
0
0
DK
I would like a fast routine to save the state of my controls to the registry. I had thought of something like this in a module:
-------------------------------------------------------
Public Sub SaveControl(Contr As Control)
SaveSetting App.EXEName, Contr.Parent.Name, Contr.Name, Contr.Value
End Sub
Public Sub LoadControl(Contr As Control)
Contr.Value = GetSetting(App.EXEName, Contr.Parent.Name, Contr.Name, Contr.Value)
End Sub
-------------------------------------------------------
and in my usercontrol a checkbox with:

Private Sub chkSimulate_Click()
ApiCalls.SaveControl (chkSimulate)
End Sub


I seem to be passing the default values of the controls instead of a reference to the control itself. Obviously I get a "Mismatch" error. Any ideas?
 
Take the parenthesis off the name of the control in your call to the sub. I.e., ApiCalls.SaveControl chkSimulate instead of ApiCalls.SaveControl (chkSimulate)
 
ApiCalls.SaveControl chkSimulate

Let op het typeOf control bij de SaveControl (een textbox heeft géén value ,maar Text )

succes Eric De Decker
vbg.be@vbgroup.nl

Licence And Copy Protection AxtiveX
Source CodeBook for the programmer
 
ok this seems to work:
Code:
Public Sub SaveControl(Contr As Control)
'save default property to registry
'routine not compatible with VB7 (but then what is...)
On Error Resume Next
If Not (Left(Contr.Tag, 1) = "b") Then 'b like in booting
    SaveSetting App.EXEName, Contr.Container.Name, Contr.Name, CStr(Contr)
End If
End Sub
Public Sub LoadControl(ByRef Contr As Control)
'load default property from registry
'routine not compatible with VB7 (but then what is...)
On Error Resume Next
    Contr.Tag = "b" 'b like in booting
       Contr = GetSetting(App.EXEName, Contr.Container.Name, Contr.Name, (Contr))
    Contr.Tag = ""
End Sub
*******************************************************
I did get ambitious and tried to load all controls ina usercontrol tagged as "Permanent" with a single sub. This did NOT work. Anybody any good ideas?

Code:
Public Sub SaveControl(Contr As UserControl)
'save default property to registry
'routine not compatible with VB7 (but then what is...)
On Error Resume Next
Dim C As Control
For Each C In Contr
    If Left(C.Tag, 1) = "p" Then 'p like in Permanent
        SaveSetting App.EXEName, Contr.Parent.Name, Contr.Name, CStr(Contr)
    End If
Next C
End Sub
Public Sub LoadControl(Contr As UserControl)
'load default property from registry
'routine not compatible with VB7 (but then what is...)
On Error Resume Next
Dim C As Control
For Each C In Contr
    If Left(C.Tag, 1) = "p" Then 'p like in Permanent
        Contr = GetSetting(App.EXEName, Contr.Parent.Name, Contr.Name, (Contr))
    End If
Next C


End Sub


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top