VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



SaveGetSettings

by Jon Webb (2 Submissions)
Category: Registry
Compatability: Visual Basic 3.0
Difficulty: Intermediate
Date Added: Wed 3rd February 2021
Rating: (6 Votes)

Fed up with saving and loading your form's settings? Well save this module and with one line of code you can save its's size and position. One more line and you save _All_ the text and check boxes values. Come on this is a great time saver - how about a vote ??? Only missing option buttion settings... maybe next week.....

Rate SaveGetSettings

Public Sub SaveValues(frmForm As Form)
'
' usage = place:
' Call SaveValues(Me)
' in the Form_Unload event
' this will save all checkbox and textbox settings
'
Dim ctlControl As Object
On Error Resume Next
For Each ctlControl In frmForm.Controls
SaveSetting App.Title, "Settings", ctlControl.Name, ctlControl.Value
'check boxes.....
SaveSetting App.Title, "Settings", ctlControl.Name, ctlControl.Text
DoEvents
Next ctlControl
End Sub
Public Sub SavePositions(frmForm As Form)
'
' usage = place:
' Call SavePositions(Me)
' in the Form_Unload event
' this will save the forms size and position
'
On Error Resume Next
If frmForm.WindowState = vbMinimized Then: Exit Sub 'don't want to come back minimized!!!
SaveSetting App.Title, "Settings", frmForm.Name & "top", frmForm.Top
SaveSetting App.Title, "Settings", frmForm.Name & "left", frmForm.Left
SaveSetting App.Title, "Settings", frmForm.Name & "width", frmForm.Width
SaveSetting App.Title, "Settings", frmForm.Name & "height", frmForm.Height
End Sub
Public Sub GetValues(frmForm As Form)
'
' usage = place:
' Call GetValues(Me)
' in the Form_Load event
' this will populate all checkbox and textbox settings
'
Dim ctlControl As Object
On Error Resume Next
For Each ctlControl In frmForm.Controls
'check boxes.....
ctlControl.Value = GetSetting(App.Title, "Settings", ctlControl.Name)
'text boxes
ctlControl.Text = GetSetting(App.Title, "Settings", ctlControl.Name)
DoEvents
Next ctlControl
End Sub
Public Sub GetPositions(frmAForm As Form)
'
' usage = place:
' Call GetPositions(Me)
' in the Form_Load event
' this will save the forms size and position
'
On Error Resume Next
frmAForm.Top = GetSetting(App.Title, "Settings", frmAForm.Name & "top", "30")
frmAForm.Left = GetSetting(App.Title, "Settings", frmAForm.Name & "left", "30")
frmAForm.Width = GetSetting(App.Title, "Settings", frmAForm.Name & "width")
frmAForm.Height = GetSetting(App.Title, "Settings", frmAForm.Name & "height")
End Sub

Download this snippet    Add to My Saved Code

SaveGetSettings Comments

No comments have been posted about SaveGetSettings. Why not be the first to post a comment about SaveGetSettings.

Post your comment

Subject:
Message:
0/1000 characters