Page 2 of 2 FirstFirst 12
Results 41 to 47 of 47

Thread: [RESOLVED] HELP with check box

  1. #41
    Fanatic Member
    Join Date
    Aug 2009
    Posts
    540

    Re: HELP with check box

    Have you set some breakpoints, stepped through your loop, and found the exact part where your app crashes?
    Where I'm from we only have one bit of advice for new comers: "If you hear banjos, turn and run".


    VS 2008 .NetFW 2.0

  2. #42

    Thread Starter
    Member
    Join Date
    May 2010
    Posts
    53

    Re: HELP with check box

    ok i got what you suggested working for the favorites folder, when i go to apply the same conditions to the rest of the check boxes no matter what i click it starts at the top, and backs up starting from top to bottom. am i missing an end somehting?

    this is the full code?

    HTML Code:
    Public Class Form1
    
    
        Dim whCB As New ChkBoxTrack
    
        Private Sub Button1_Click(ByVal sender As System.Object, _
                                  ByVal e As System.EventArgs) Handles start.Click
    
            If mydocuments.Checked = True Then
    
            End If
            '
            ' Check to see if the directory exists. If it does not, create it
            '
            Dim folderExists As Boolean
            folderExists = My.Computer.FileSystem.DirectoryExists("h:\test\My Documents")
            If folderExists = False Then
                My.Computer.FileSystem.CreateDirectory(CStr(folderExists))
            End If
            '
            ' Parse out the path from the filename and copy the files.
            '
            Try
                My.Computer.FileSystem.CopyDirectory("c:\documents and settings\godboubs\My Documents", "h:\test\My Documents", True)
            Catch ex As ApplicationException
                MsgBox(ex.Message, MsgBoxStyle.Exclamation)
            End Try
    
            '
            ' Same follows but for different chk boxes and directories*******************
            '
            If desktop.Checked = True Then
                '
                ' Check to see if the directory exists. If it does not, create it
                '
                folderExists = My.Computer.FileSystem.DirectoryExists("h:\test\Desktop")
                If folderExists = False Then
                    My.Computer.FileSystem.CreateDirectory(CStr(folderExists))
                End If
                '
                ' Parse out the path from the filename and copy the files.
                '
                Try
                    My.Computer.FileSystem.CopyDirectory("c:\documents and settings\godboubs\Desktop", "h:\test\Desktop", True)
                Catch ex As ApplicationException
                    MsgBox(ex.Message, MsgBoxStyle.Exclamation)
                End Try
            End If
            '
            ' ****************************************************************************
            '
            If favorites.Checked = True Then
                '
                ' Check to see if the directory exists. If it does not, create it
                '
                folderExists = My.Computer.FileSystem.DirectoryExists("h:\test\favorites")
                If folderExists = False Then
                    My.Computer.FileSystem.CreateDirectory(CStr(folderExists))
                End If
                '
                ' Parse out the path from the filename and copy the files.
                '
                Try
                    My.Computer.FileSystem.CopyDirectory("c:\documents and settings\godboubs\favorites", "h:\test\favorites", True)
                Catch ex As ApplicationException
                    MsgBox(ex.Message, MsgBoxStyle.Exclamation)
                End Try
            End If
            '
            ' ****************************************************************************
            '
            If nethood.Checked = True Then
                '
                ' Check to see if the directory exists. If it does not, create it
                '
                folderExists = My.Computer.FileSystem.DirectoryExists("h:\test\Nethood")
                If folderExists = False Then
                    My.Computer.FileSystem.CreateDirectory(CStr(folderExists))
                End If
                '
                ' Parse out the path from the filename and copy the files.
                '
                Try
                    My.Computer.FileSystem.CopyDirectory("c:\documents and settings\godboubs\Nethood", "h:\test\Nethood", True)
                Catch ex As ApplicationException
                    MsgBox(ex.Message, MsgBoxStyle.Exclamation)
                End Try
            End If
            '
            ' ****************************************************************************
            '
            If miscoutlook.Checked = True Then
                '
                ' Check to see if the directory exists. If it does not, create it
                '
                folderExists = My.Computer.FileSystem.DirectoryExists("h:\test\Outlook")
                If folderExists = False Then
                    My.Computer.FileSystem.CreateDirectory(CStr(folderExists))
                End If
                '
                ' Parse out the path from the filename and copy the files.
                '
                Try
                    My.Computer.FileSystem.CopyDirectory("c:\documents and settings\godboubs\outlook", "h:\test\Outlook", True)
                Catch ex As ApplicationException
                    MsgBox(ex.Message, MsgBoxStyle.Exclamation)
                End Try
            End If
    
        End Sub
    
        Private Sub CheckBox1_CheckedChanged(ByVal sender As System.Object, _
                                             ByVal e As System.EventArgs) _
                                            Handles mydocuments.CheckedChanged, _
                                                            desktop.CheckedChanged, _
                                                            favorites.CheckedChanged, _
                                                            nethood.CheckedChanged, _
                                                            miscoutlook.CheckedChanged
            Dim cb As CheckBox = DirectCast(sender, CheckBox)
            Select Case cb.Name
                Case "mydocuments"
                    If cb.Checked Then whCB.SetB(_cbCHK.cb1) Else whCB.ClearB(_cbCHK.cb1)
                Case "desktop"
                    If cb.Checked Then whCB.SetB(_cbCHK.cb2) Else whCB.ClearB(_cbCHK.cb2)
                Case "favorites"
                    If cb.Checked Then whCB.SetB(_cbCHK.cb3) Else whCB.ClearB(_cbCHK.cb3)
                Case "nethood"
                    If cb.Checked Then whCB.SetB(_cbCHK.cb4) Else whCB.ClearB(_cbCHK.cb4)
                Case "miscoutlook"
                    If cb.Checked Then whCB.SetB(_cbCHK.cb5) Else whCB.ClearB(_cbCHK.cb5)
            End Select
            Debug.WriteLine(whCB.toStringCB)
        End Sub
    
        Private Sub Form1_Load(ByVal sender As System.Object, _
                               ByVal e As System.EventArgs) Handles MyBase.Load
    
            'in case the default checkbox state is not off
            For Each c In Me.Controls
                If TypeOf c Is CheckBox Then
                    DirectCast(c, CheckBox).Checked = Not DirectCast(c, CheckBox).Checked
                    DirectCast(c, CheckBox).Checked = Not DirectCast(c, CheckBox).Checked
                End If
            Next
    
        End Sub
    
        Private Sub Label2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
    
        End Sub
    End Class
    
    Class ChkBoxTrack
    
        Private _myCB As _cbCHK
        'set the bit
        Public Function SetB(ByVal WhBox As _cbCHK) As _cbCHK
            Me._myCB = Me._myCB Or WhBox
        End Function
        'clear the bit
        Public Function ClearB(ByVal WhBox As _cbCHK) As _cbCHK
            Me._myCB = Me._myCB And (WhBox Xor _cbCHK.allCB)
        End Function
        'test the bit
        Public Function IsOn(ByVal WhBox As _cbCHK) As Boolean
            If (Me._myCB And WhBox) = WhBox Then Return True Else Return False
        End Function
        'show on bits as string
        Public Function toStringCB() As String
            Return Me._myCB.ToString
        End Function
        'get the setting
        ReadOnly Property Getb() As _cbCHK
            Get
                Return Me._myCB
            End Get
        End Property
    End Class
    
    <FlagsAttribute()> _
    Public Enum _cbCHK As Integer
        noCBchked = 0
        cb1 = 1 << 1
        cb2 = 1 << 2
        cb3 = 1 << 3
        cb4 = 1 << 4
        cb5 = 1 << 5
        allCB = cb1 Or cb2 Or cb3 Or cb4 Or cb5
    End Enum

  3. #43
    Hyperactive Member mbutler755's Avatar
    Join Date
    May 2008
    Location
    Peoria, AZ
    Posts
    417

    Re: HELP with check box

    Quote Originally Posted by littlejob View Post
    ok i got what you suggested working for the favorites folder, when i go to apply the same conditions to the rest of the check boxes no matter what i click it starts at the top, and backs up starting from top to bottom. am i missing an end somehting?

    this is the full code?

    HTML Code:
    Public Class Form1
    
    
        Dim whCB As New ChkBoxTrack
    
        Private Sub Button1_Click(ByVal sender As System.Object, _
                                  ByVal e As System.EventArgs) Handles start.Click
    
            If mydocuments.Checked = True Then
    
            End If
            '
            ' Check to see if the directory exists. If it does not, create it
            '
            Dim folderExists As Boolean
            folderExists = My.Computer.FileSystem.DirectoryExists("h:\test\My Documents")
            If folderExists = False Then
                My.Computer.FileSystem.CreateDirectory(CStr(folderExists))
            End If
            '
            ' Parse out the path from the filename and copy the files.
            '
            Try
                My.Computer.FileSystem.CopyDirectory("c:\documents and settings\godboubs\My Documents", "h:\test\My Documents", True)
            Catch ex As ApplicationException
                MsgBox(ex.Message, MsgBoxStyle.Exclamation)
            End Try
    
            '
            ' Same follows but for different chk boxes and directories*******************
            '
            If desktop.Checked = True Then
                '
                ' Check to see if the directory exists. If it does not, create it
                '
                folderExists = My.Computer.FileSystem.DirectoryExists("h:\test\Desktop")
                If folderExists = False Then
                    My.Computer.FileSystem.CreateDirectory(CStr(folderExists))
                End If
                '
                ' Parse out the path from the filename and copy the files.
                '
                Try
                    My.Computer.FileSystem.CopyDirectory("c:\documents and settings\godboubs\Desktop", "h:\test\Desktop", True)
                Catch ex As ApplicationException
                    MsgBox(ex.Message, MsgBoxStyle.Exclamation)
                End Try
            End If
            '
            ' ****************************************************************************
            '
            If favorites.Checked = True Then
                '
                ' Check to see if the directory exists. If it does not, create it
                '
                folderExists = My.Computer.FileSystem.DirectoryExists("h:\test\favorites")
                If folderExists = False Then
                    My.Computer.FileSystem.CreateDirectory(CStr(folderExists))
                End If
                '
                ' Parse out the path from the filename and copy the files.
                '
                Try
                    My.Computer.FileSystem.CopyDirectory("c:\documents and settings\godboubs\favorites", "h:\test\favorites", True)
                Catch ex As ApplicationException
                    MsgBox(ex.Message, MsgBoxStyle.Exclamation)
                End Try
            End If
            '
            ' ****************************************************************************
            '
            If nethood.Checked = True Then
                '
                ' Check to see if the directory exists. If it does not, create it
                '
                folderExists = My.Computer.FileSystem.DirectoryExists("h:\test\Nethood")
                If folderExists = False Then
                    My.Computer.FileSystem.CreateDirectory(CStr(folderExists))
                End If
                '
                ' Parse out the path from the filename and copy the files.
                '
                Try
                    My.Computer.FileSystem.CopyDirectory("c:\documents and settings\godboubs\Nethood", "h:\test\Nethood", True)
                Catch ex As ApplicationException
                    MsgBox(ex.Message, MsgBoxStyle.Exclamation)
                End Try
            End If
            '
            ' ****************************************************************************
            '
            If miscoutlook.Checked = True Then
                '
                ' Check to see if the directory exists. If it does not, create it
                '
                folderExists = My.Computer.FileSystem.DirectoryExists("h:\test\Outlook")
                If folderExists = False Then
                    My.Computer.FileSystem.CreateDirectory(CStr(folderExists))
                End If
                '
                ' Parse out the path from the filename and copy the files.
                '
                Try
                    My.Computer.FileSystem.CopyDirectory("c:\documents and settings\godboubs\outlook", "h:\test\Outlook", True)
                Catch ex As ApplicationException
                    MsgBox(ex.Message, MsgBoxStyle.Exclamation)
                End Try
            End If
    
        End Sub
    
        Private Sub CheckBox1_CheckedChanged(ByVal sender As System.Object, _
                                             ByVal e As System.EventArgs) _
                                            Handles mydocuments.CheckedChanged, _
                                                            desktop.CheckedChanged, _
                                                            favorites.CheckedChanged, _
                                                            nethood.CheckedChanged, _
                                                            miscoutlook.CheckedChanged
            Dim cb As CheckBox = DirectCast(sender, CheckBox)
            Select Case cb.Name
                Case "mydocuments"
                    If cb.Checked Then whCB.SetB(_cbCHK.cb1) Else whCB.ClearB(_cbCHK.cb1)
                Case "desktop"
                    If cb.Checked Then whCB.SetB(_cbCHK.cb2) Else whCB.ClearB(_cbCHK.cb2)
                Case "favorites"
                    If cb.Checked Then whCB.SetB(_cbCHK.cb3) Else whCB.ClearB(_cbCHK.cb3)
                Case "nethood"
                    If cb.Checked Then whCB.SetB(_cbCHK.cb4) Else whCB.ClearB(_cbCHK.cb4)
                Case "miscoutlook"
                    If cb.Checked Then whCB.SetB(_cbCHK.cb5) Else whCB.ClearB(_cbCHK.cb5)
            End Select
            Debug.WriteLine(whCB.toStringCB)
        End Sub
    
        Private Sub Form1_Load(ByVal sender As System.Object, _
                               ByVal e As System.EventArgs) Handles MyBase.Load
    
            'in case the default checkbox state is not off
            For Each c In Me.Controls
                If TypeOf c Is CheckBox Then
                    DirectCast(c, CheckBox).Checked = Not DirectCast(c, CheckBox).Checked
                    DirectCast(c, CheckBox).Checked = Not DirectCast(c, CheckBox).Checked
                End If
            Next
    
        End Sub
    
        Private Sub Label2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
    
        End Sub
    End Class
    
    Class ChkBoxTrack
    
        Private _myCB As _cbCHK
        'set the bit
        Public Function SetB(ByVal WhBox As _cbCHK) As _cbCHK
            Me._myCB = Me._myCB Or WhBox
        End Function
        'clear the bit
        Public Function ClearB(ByVal WhBox As _cbCHK) As _cbCHK
            Me._myCB = Me._myCB And (WhBox Xor _cbCHK.allCB)
        End Function
        'test the bit
        Public Function IsOn(ByVal WhBox As _cbCHK) As Boolean
            If (Me._myCB And WhBox) = WhBox Then Return True Else Return False
        End Function
        'show on bits as string
        Public Function toStringCB() As String
            Return Me._myCB.ToString
        End Function
        'get the setting
        ReadOnly Property Getb() As _cbCHK
            Get
                Return Me._myCB
            End Get
        End Property
    End Class
    
    <FlagsAttribute()> _
    Public Enum _cbCHK As Integer
        noCBchked = 0
        cb1 = 1 << 1
        cb2 = 1 << 2
        cb3 = 1 << 3
        cb4 = 1 << 4
        cb5 = 1 << 5
        allCB = cb1 Or cb2 Or cb3 Or cb4 Or cb5
    End Enum
    Think about it this way, you need to evaluate a property to see if it is true. If it is, then you need to execute the code. It should look more like this:

    vb.net Code:
    1. If SomeCheckbox.checked=true then
    2.   ' perform the backup here
    3. End If
    4.  
    5. If SomeOtherCheckbox.Checked=true then
    6.   ' perform the backup for SomeOtherCheckbox here
    7. End If

    Each of the backups should be encased in If/Then statements that evaluate whether or not the checkbox is checked or not. If it is checked, it runs the code inside of the If/Then statement.
    Regards,

    Matt Butler, MBA, BSIT/SE, MCBP
    Owner, Intense IT, LLC
    Find us on Facebook
    Follow us on Twitter
    Link up on LinkedIn
    mb (at) i2t.us

    CODE BANK SUBMISSIONS: Converting Images to Base64 and Back Again

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

    Re: HELP with check box

    What is a shame is that this wasn't two threads. The original question was "I now need help with the if then statements. Once the user selects what they want then i need "Start Backup" t run the selected code." Which was answered by several people.

    The file / folder / copy business should have been a new thread.
    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. #45
    Hyperactive Member mbutler755's Avatar
    Join Date
    May 2008
    Location
    Peoria, AZ
    Posts
    417

    Re: HELP with check box

    Quote Originally Posted by dbasnett View Post
    What is a shame is that this wasn't two threads. The original question was "I now need help with the if then statements. Once the user selects what they want then i need "Start Backup" t run the selected code." Which was answered by several people.

    The file / folder / copy business should have been a new thread.
    Agreed. None of us told the OP to separate out the threads though.
    Regards,

    Matt Butler, MBA, BSIT/SE, MCBP
    Owner, Intense IT, LLC
    Find us on Facebook
    Follow us on Twitter
    Link up on LinkedIn
    mb (at) i2t.us

    CODE BANK SUBMISSIONS: Converting Images to Base64 and Back Again

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

    Re: HELP with check box

    Quote Originally Posted by mbutler755 View Post
    Agreed. None of us told the OP to separate out the threads though.
    I plead guilty. Just a shame.
    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. #47

    Thread Starter
    Member
    Join Date
    May 2010
    Posts
    53

    Re: HELP with check box

    Code:
    Dim folderExists As Boolean
    i had to move this line above the first if statement so i guess it applied to all..working now..

    NOW i will open new thread for different problems.

    thank you

Page 2 of 2 FirstFirst 12

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