Results 1 to 10 of 10

Thread: On to my Last Question. (Hopefully)

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Jun 2010
    Posts
    29

    On to my Last Question. (Hopefully)

    Ok. So, how do i save things. Ive made a Checked Item Box. But i can't get any of the things to Save that i have Checked?

    Keep in mind im a Newbe at all this.

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: On to my Last Question. (Hopefully)

    Please provide meaningful titles for your thread. Whether or not it;s your last question is neither here nor there. The thread title is supposed to let us know what the thread is about without having to actually open it. Without meaningful thread titles we'd have to open every thread to find out which ones were relevant to us.

    As for the question, you're going to have to provide more information. You say that you can;t get things to save but you give no indication of what you've tried, so we have no idea of what you might be doing wrong. Also, you give no real indication of what you want to save and where. Saving could be done in a database, to a text file or many other things. If you don't know where you want to save the data then you need to say so so we know that you want us to provide suggestions on the where as well as the how. When posting, keep the words "full and clear description" foremost in your mind and you will have the best chance of getting the help you want as quickly as possible.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Jun 2010
    Posts
    29

    Re: On to my Last Question. (Hopefully)

    Sorry.

    Easiest place to save i guess for a Newbe.
    I haven't Tried anything, Because i don't know how to get it to save.
    All i need saved is a checks for a CheckedListBox. About 30 or so of them.

  4. #4
    Powered By Medtronic dbasnett's Avatar
    Join Date
    Dec 2007
    Location
    Jefferson City, MO
    Posts
    9,897

    Re: On to my Last Question. (Hopefully)

    Code:
    Public Class Form1
    
        Private Sub Button1_Click(ByVal sender As System.Object, _
                                  ByVal e As System.EventArgs) _
                              Handles Button1.Click
            'generate some checkboxes to test with
            For x As Integer = 1 To 64
                CheckedListBox1.Items.Add(x.ToString)
            Next
        End Sub
    
    
        Private Sub Button2_Click(ByVal sender As System.Object, _
                                  ByVal e As System.EventArgs) Handles Button2.Click
    
            'save the item state - this works for up to 64 boxes
            Dim chkLBstate As Long = 0L 'set initial state to none
    
            For Each idx As Integer In CheckedListBox1.CheckedIndices 'get the items checked
                chkLBstate = chkLBstate Or (1L << idx) 'turn the bit on 
            Next
            My.Settings.SavedButton = chkLBstate 'save
            My.Settings.Save()
        End Sub
    
        Private Sub Button3_Click(ByVal sender As System.Object, _
                                  ByVal e As System.EventArgs) Handles Button3.Click
            'reload
    
            Dim chkLBstate As Long = My.Settings.SavedButton 'get saved
    
            For x As Integer = 0 To 63 'check the bits
                Dim aBit As Long = 1L << x
                If (aBit And chkLBstate) = aBit Then
                    CheckedListBox1.SetItemChecked(x, True)
                Else
                    CheckedListBox1.SetItemChecked(x, False)
                End If
            Next
        End Sub
    End Class
    And / Or / etc.

    Shift << >>
    Last edited by dbasnett; Jun 28th, 2010 at 11:58 AM.
    My First Computer -- Documentation Link (RT?M) -- Using the Debugger -- Prime Number Sieve
    Counting Bits -- Subnet Calculator -- UI Guidelines -- >> SerialPort Answer <<

    "Those who use Application.DoEvents have no idea what it does and those who know what it does never use it." John Wein

  5. #5

    Thread Starter
    Junior Member
    Join Date
    Jun 2010
    Posts
    29

    Re: On to my Last Question. (Hopefully)

    No idea. What any of that means.
    Like i said. im a Newbe at all this so. Your going to have to Explain to me what each does or going to do.

  6. #6
    Powered By Medtronic dbasnett's Avatar
    Join Date
    Dec 2007
    Location
    Jefferson City, MO
    Posts
    9,897

    Re: On to my Last Question. (Hopefully)

    Start by creating a new application. On the form add three buttons and 1 checkedlistbox. Copy and paste the code. Using the debugger set breakpoints at the beginning of each button.

    Button1 just creates some checkboxes for testing

    Button2 saves which boxes are checked when it is pressed

    Button3 reloads what was saved by button2.

    I posted two links. Did you read them?
    My First Computer -- Documentation Link (RT?M) -- Using the Debugger -- Prime Number Sieve
    Counting Bits -- Subnet Calculator -- UI Guidelines -- >> SerialPort Answer <<

    "Those who use Application.DoEvents have no idea what it does and those who know what it does never use it." John Wein

  7. #7

    Thread Starter
    Junior Member
    Join Date
    Jun 2010
    Posts
    29

    Re: On to my Last Question. (Hopefully)

    Personally. I don't want the round about way of doing it.
    I just want these check boxes to be able to save after exiting of the Program.
    Its going to be a way for me to keep track of the games, ive beat in the Mega Man Universe.
    I don't want to write them down anymore and loose the Piece of Paper i was Jotted down on.
    If there's a Simple and to the Point way for a Complete Newbe to understand. I'd like to see it.
    Otherwise. You'll have to explain what you said. All this is Greek to me.

  8. #8
    Powered By Medtronic dbasnett's Avatar
    Join Date
    Dec 2007
    Location
    Jefferson City, MO
    Posts
    9,897

    Re: On to my Last Question. (Hopefully)

    Quote Originally Posted by Exodus Death View Post
    Personally. I don't want the round about way of doing it.
    I just want these check boxes to be able to save after exiting of the Program.
    Its going to be a way for me to keep track of the games, ive beat in the Mega Man Universe.
    I don't want to write them down anymore and loose the Piece of Paper i was Jotted down on.
    If there's a Simple and to the Point way for a Complete Newbe to understand. I'd like to see it.
    Otherwise. You'll have to explain what you said. All this is Greek to me.
    Show me the code you have so far.
    My First Computer -- Documentation Link (RT?M) -- Using the Debugger -- Prime Number Sieve
    Counting Bits -- Subnet Calculator -- UI Guidelines -- >> SerialPort Answer <<

    "Those who use Application.DoEvents have no idea what it does and those who know what it does never use it." John Wein

  9. #9
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: On to my Last Question. (Hopefully)

    dbasnett is suggesting that you use a single number as a series of flags, each representing the checked state of one of items in your CheckedListBox. Remember that all numbers are stored in binary form in a computer, i.e. a series of bits that can each be 0 or 1. If you think of 0 as False and 1 as True, each of those bits can be used to represent a Boolean value, e.g. the checked state of an item in a CheckedListBox.

    Not that bitwise operations are especially hard once you understand them, but there's actually an easier way. The .NET Framework provides the BitArray class and BitVector32 structure for working with bits. If you have 32 flags or less to deal with, the BitVector32 is probably your best option.

    So, assuming you have added a Setting of type Integer named Flags to your project, you can set the checked state of each item in a CheckedListBox like so:
    vb.net Code:
    1. Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    2.     Dim flags As New Specialized.BitVector32(My.Settings.Flags)
    3.  
    4.     For index As Integer = 0 To Me.CheckedListBox1.Items.Count - 1
    5.         Me.CheckedListBox1.SetItemChecked(index, flags(CInt(2 ^ index)))
    6.     Next
    7. End Sub
    and then save them like so:
    vb.net Code:
    1. Private Sub Form1_FormClosed(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosedEventArgs) Handles Me.FormClosed
    2.     Dim flags As New Specialized.BitVector32
    3.  
    4.     For index As Integer = 0 To Me.CheckedListBox1.Items.Count - 1
    5.         flags(CInt(2 ^ index)) = Me.CheckedListBox1.GetItemChecked(index)
    6.     Next
    7.  
    8.     My.Settings.Flags = flags.Data
    9. End Sub
    Note how I access the items in the BitVector32. Rather than flags(index) I use flags(CInt(2 ^ index)). That's because the index is a bitmask. That means that the binary form indicates which bit to get. The 8-bit binary forms of 1, 2, 4, 8, 16, 32, 64 and 128 are:
    Code:
    00000001
    00000010
    00000100
    00001000
    00010000
    00100000
    01000000
    10000000
    so you can see how each one represents a single bit. You can set multiple bits simultaneously by using numbers other than round powers of 2.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  10. #10

    Thread Starter
    Junior Member
    Join Date
    Jun 2010
    Posts
    29

    Re: On to my Last Question. (Hopefully)

    Thank you So. so. so. Much. I modified it a bit because i have Multipile CheckListBoxes inside a Tab Control.
    So i Named the First FlagC and then FlagX and made new For Statements for them and it works as well.
    Saved Each just like i want.

    Thank you so much for heh, Putting up with me.

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