save checkboxes as custom option
I have a form with multiple checkboxes what I would like to do is to have it that if someone selects any combination of the checkboxes they could save those selections by pressing a button named save options or something to that affect it would then save those selections then they could load them by pressing another button load options and run them with another button named run options (or the box that loads could run too) not sure the best way to do it
the goal is ultimately to have a button that allows the state of the checkboxes to be saved and then run as a custom option.
how would I do this I cannot find anything on the internet ?
Re: save checkboxes as custom option
I have something similar for individual users of my application. What I did was I used check boxes to restrict access to the application thus:
Code:
iif(checkbox.checked = true,true,false)
and these are saved to the individual. So when they logon, if the check box is checked they have access.
Using the above statement for each check box and saving it to a file should work.
Computerman :)
Re: save checkboxes as custom option
My.Settings could be used, depending on how user-specific you want to go. If this is a matter of saving settings that can be restored the next time you run the program, My.Settings would work fine. If you want to be able to store a variety of different 'configurations', then I would be inclined to put the configuration settings into a structure, and serialzie the structure to a file. That could be made into a pretty complex animal, if needed.
Re: save checkboxes as custom option
vb.net Code:
'To save
Dim c As Control
Dim sw As New IO.StreamWriter("/settingsfile.dat")
For Each c In Me.grpCheckBoxContainer.Controls
If TypeOf c Is CheckBox Then
sw.WriteLine(DirectCast(c,CheckBox).Checked.ToString())
End If
Next
sw.Close()
sw.Dispose()
'To load
Dim sr As New IO.StreamReader("/settingsfile.dat"), i As Integer = 0
While sr.Peek() > -1
If sr.ReadLine() = Boolean.TrueString Then
Me.grpCheckBoxContainer.Controls("chkCheckBox" & i).Checked = True
Else
Me.grpCheckBoxContainer.Controls("chkCheckBox" & i).Checked = False
End If
i += 1
End While
sr.Close()
sr.Dispose()
For this example to work, your checkboxes must be in a GroupBox or Panel named grpCheckBoxContainer and your checkboxes' names must be chkCheckBox1, chkCheckBox2, etc., but you can easily change those.
Re: save checkboxes as custom option
minitech,
they are all individual checkboxes so I don't believe what you posted will work.
Shaggy Hiker,
I'm looking to make it so you could save individual configurations and then run them by clicking a button that says custom this way it can be custom tailored to any selection of options.
computerman,
Im not understanding the logic in the example you posted
Code:
iif(checkbox.checked = true,true,false)
what does the true true false do and how would I save this file ?
Re: save checkboxes as custom option
You don't believe it will work, but have you tried? It does. :)
iif(checkbox.checked = true,true,false) does nothing, you can replace it with checkbox.checked. IIf is unnecessary.
2 Attachment(s)
Re: save checkboxes as custom option
My logic was wrong. It should have read:
Code:
booleanvariable1=iif(checkbox1.checked = true,true,false)
booleanvariable2=iif(checkbox2.checked = true,true,false)
what this means is if the check box is checked then the boolean value is true, if it is not then it is false.
So you would save the booleanvariable to a file. You would do this for each boolean variable.
So when you want to retrieve the booleanvariable in the file the code would read:
Code:
checkbox.checked = iif(booleanvariable= true,true,false)
etc
If you look at the attached image you can see how the check boxes are used for individual users for my application. I have also supplied the code for that form.
I hope it is of use.
Computerman
Re: save checkboxes as custom option
minitech,
you said this
"your checkboxes must be in a GroupBox or Panel named grpCheckBoxContainer "
my checkboxes aren't in a groupbox or Panel you said they must be in those for it to work that is why i said it wont work in my situation.
Re: save checkboxes as custom option
Computerman,
Ok I get the boolean part but how do I save it to a file ? and how do I retrieve that file, sorry for so many questions just started VB at the beginning of this month.
(offtopic) I can't beleive how many things are not in the books.
Re: save checkboxes as custom option
Have you tried creating a database? You could save the values as boolean type in it, saving you a lot of trouble.
Hope that helps :).
Re: save checkboxes as custom option
Have you had a look at the code attached on my previous post. It will give you an idea how to do it. It may not be the best, but it does work.
Computerman :)
Re: save checkboxes as custom option
Computerman,
I looked at the code but I cannot see where the settings are being saved
Re: save checkboxes as custom option
In the part where you change the application name click on the Settings tab and you'll see the settings.