-
hi
is there anyone out there who might be kind enough to write a small example of how to save and retreive the value of a checkbox on a form(checked or unchecked)so that the same condition is returned the next time the app. is run 'cos i am really struggling with this one folks!!
Thanks in advance for any help
-
Code:
Private Sub Form_Load()
Dim value As String
Open App.Path & "\options.txt" For Input As #1
Input #1, value
Check1.value = value
Close
End Sub
Private Sub Form_Unload(Cancel As Integer)
Open App.Path & "\options.txt" For Output As #1
Print #1, Check1.value
Close
End Sub
Create a file, options.txt in the path of your app with 0 or 1 in it (only needed the first time) and then run the code and VOILA!
-
Is there a specific reason why you want this in a file? If not use the Registry
Code:
SaveSetting App.Title, "Settings", "CheckBoxState", check1.value
check1.value = GetSetting(App.Title, "Settings", "CheckBoxState", vbUnchecked)
-
Yeah you're right, the registry is a better Idea, but what's this?
Code:
check1.value = GetSetting(App.Title, "Settings", "CheckBoxState", vbUnchecked)
Wouldn't that always get the vbUnchecked in the checkbox?
-
Code:
check1.value = GetSetting(App.Title, "Settings", "CheckBoxState", vbUnchecked)
SaveSetting App.Title, "Settings", "CheckBoxState", check1.value
try those
-
why vbUnChecked
PRIVATE1, I'm with Jop, wouldn't that always open the form with the checkbox unchecked?
-
No. The vbunchecked bit would be the default value. ie. if the GetSetting is performed in the form_load event and the app has never been used before there will not be a registry setting, therefore GetSetting returns 'unchecked'. The SaveSetting will create a registry entry if there isn't one or update one if there is.
Took a while to respond - time lapse between England's hard fought heroic point against the mighty Fins, food, and the Jocks putting us to shame with a good performance against a side just a tad better than Finland.
-
I'm a kind person :rolleyes:.
Take a look at this thread.