Results 1 to 13 of 13

Thread: save checkboxes as custom option

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Aug 2009
    Posts
    173

    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 ?

  2. #2
    Hyperactive Member
    Join Date
    Dec 2007
    Location
    Somewhere else today
    Posts
    355

    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
    It was much easier in VB6, but I am now liking Vb.Net alot more.

  3. #3
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    40,104

    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.
    My usual boring signature: Nothing

  4. #4
    Stack Overflow mod​erator
    Join Date
    May 2008
    Location
    British Columbia, Canada
    Posts
    2,824

    Talking Re: save checkboxes as custom option

    vb.net Code:
    1. 'To save
    2. Dim c As Control
    3. Dim sw As New IO.StreamWriter("/settingsfile.dat")
    4. For Each c In Me.grpCheckBoxContainer.Controls
    5.        If TypeOf c Is CheckBox Then
    6.               sw.WriteLine(DirectCast(c,CheckBox).Checked.ToString())
    7.        End If
    8. Next
    9. sw.Close()
    10. sw.Dispose()
    11.  
    12. 'To load
    13. Dim sr As New IO.StreamReader("/settingsfile.dat"), i As Integer = 0
    14. While sr.Peek() > -1
    15.        If sr.ReadLine() = Boolean.TrueString Then
    16.               Me.grpCheckBoxContainer.Controls("chkCheckBox" & i).Checked = True
    17.        Else
    18.               Me.grpCheckBoxContainer.Controls("chkCheckBox" & i).Checked = False
    19.        End If
    20.        i += 1
    21. End While
    22. sr.Close()
    23. 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.

  5. #5

    Thread Starter
    Addicted Member
    Join Date
    Aug 2009
    Posts
    173

    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 ?

  6. #6
    Stack Overflow mod​erator
    Join Date
    May 2008
    Location
    British Columbia, Canada
    Posts
    2,824

    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.

  7. #7
    Hyperactive Member
    Join Date
    Dec 2007
    Location
    Somewhere else today
    Posts
    355

    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
    Attached Images Attached Images  
    Attached Files Attached Files
    It was much easier in VB6, but I am now liking Vb.Net alot more.

  8. #8

    Thread Starter
    Addicted Member
    Join Date
    Aug 2009
    Posts
    173

    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.

  9. #9

    Thread Starter
    Addicted Member
    Join Date
    Aug 2009
    Posts
    173

    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.

  10. #10
    Fanatic Member
    Join Date
    Oct 2008
    Location
    Dominican Republic
    Posts
    733

    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 .
    "In our profession, precision and perfection are not a dispensable luxury, but a simple necessity."
    Niklaus E. Wirth


    Rate any post that helped you, it's a good way of saying thanks
    Please specify your Visual Studio Version!

    Why rating is useful

    My Code Bank Submissions: How to determine Windows Version| Working With Mouse Events | Blocking Input Using API | Get host's IP | Minimize to system tray "animated" | Colored ListBox (custom fonts, colors, highlight) Updated -New Class! | [VS 2008] Strong encryption and hashing class - Updated! 31/August/2009 | Create a shortcut using IWshRuntimeLibrary

  11. #11
    Hyperactive Member
    Join Date
    Dec 2007
    Location
    Somewhere else today
    Posts
    355

    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
    It was much easier in VB6, but I am now liking Vb.Net alot more.

  12. #12

    Thread Starter
    Addicted Member
    Join Date
    Aug 2009
    Posts
    173

    Re: save checkboxes as custom option

    Computerman,

    I looked at the code but I cannot see where the settings are being saved

  13. #13
    Fanatic Member
    Join Date
    Oct 2008
    Location
    Dominican Republic
    Posts
    733

    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.
    "In our profession, precision and perfection are not a dispensable luxury, but a simple necessity."
    Niklaus E. Wirth


    Rate any post that helped you, it's a good way of saying thanks
    Please specify your Visual Studio Version!

    Why rating is useful

    My Code Bank Submissions: How to determine Windows Version| Working With Mouse Events | Blocking Input Using API | Get host's IP | Minimize to system tray "animated" | Colored ListBox (custom fonts, colors, highlight) Updated -New Class! | [VS 2008] Strong encryption and hashing class - Updated! 31/August/2009 | Create a shortcut using IWshRuntimeLibrary

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width