Categories: MSDN / DotNet / Java / Scripts / Linux / PHP Ask - La ask - La Answer

Need Help Saving Values In Controls

Ok I am very very slow when it comes to VB6. I had basic basic training 5 years ago and I am starting to get back into it.

What I need to do is create a very simple program so when a user enters values into textboxes or values from any other control, I want to be able to save those values and each time the program is run, it loads those values that were entered last.

Can anyone please, please give me a hand with this. I don't think its that difficult but as I said, not using VB for 5 years, well yeah I am rusty and need some lead way.
[565 byte] By [StylinLancer] at [2007-11-11 7:37:36]
# 1 Re: Need Help Saving Values In Controls
I Googled for "vb textbox load save file" and found this:
http://www.codearchive.com/rate.php?rid=2&go=0208
Phil Weber at 2007-11-11 17:26:42 >
# 2 Re: Need Help Saving Values In Controls
Not sure what I am doing wrong but it seems I keep getting an error. I am using a cmd buttom with the code you supplied to me yet I get errors. Any suggestions?
StylinLancer at 2007-11-11 17:27:39 >
# 3 Re: Need Help Saving Values In Controls
You'll have to be more specific: What does the error message say? On which line of code does it occur?
Phil Weber at 2007-11-11 17:28:38 >
# 4 Re: Need Help Saving Values In Controls
to save values you can just use windows registers it's not difficult.
goast at 2007-11-11 17:29:43 >
# 5 Re: Need Help Saving Values In Controls
How do you go about using the windows registry?
StylinLancer at 2007-11-11 17:30:41 >
# 6 Re: Need Help Saving Values In Controls
http://www.google.com/search?q=vb+registry
Phil Weber at 2007-11-11 17:31:51 >
# 7 Re: Need Help Saving Values In Controls
'This example shows how you can save and retieve program setting variable etc
'The values are saved in the Registry for the application
'Read up on the SaveSetting and Getsetting for clarification of the aguments to the Functions
'Best of luck .. hope it was some help to you
'Creat a new for with 2 text boxes, one check box and a Command button with a caption of exit
'and paste the following code :)
'Try changing the size of the form, the text and check, exit the program and run it again
'and see what happens

Option Explicit

Private Sub Command1_Click()
If Me.WindowState <> vbMinimized Then
SaveSetting App.Title, "Settings", "MainLeft", Me.Left
SaveSetting App.Title, "Settings", "MainTop", Me.Top
SaveSetting App.Title, "Settings", "MainWidth", Me.Width
SaveSetting App.Title, "Settings", "MainHeight", Me.Height
End If
SaveSetting App.Title, "ProgVars", "Check1", Check1.Value
SaveSetting App.Title, "ProgVars", "Text1", Text1.Text
SaveSetting App.Title, "ProgVars", "Text2", Text2.Text
End
End Sub

Private Sub Form_Load()
Me.Left = GetSetting(App.Title, "Settings", "MainLeft", 500)
Me.Top = GetSetting(App.Title, "Settings", "MainTop", 500)
Me.Width = GetSetting(App.Title, "Settings", "MainWidth", 3250)
Me.Height = GetSetting(App.Title, "Settings", "MainHeight", 3250)

Check1.Value = GetSetting(App.Title, "ProgVars", "Check1", Checked)
Text1.Text = GetSetting(App.Title, "ProgVars", "Text1", "")
Text2.Text = GetSetting(App.Title, "ProgVars", "Text2", "")
End Sub
milton at 2007-11-11 17:32:44 >
# 8 Re: Need Help Saving Values In Controls
Thanks. I'll give this a try and let you know.
StylinLancer at 2007-11-11 17:33:49 >