Have you set some breakpoints, stepped through your loop, and found the exact part where your app crashes?
Printable View
Have you set some breakpoints, stepped through your loop, and found the exact part where your app crashes?
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:
If SomeCheckbox.checked=true then ' perform the backup here End If If SomeOtherCheckbox.Checked=true then ' perform the backup for SomeOtherCheckbox here 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.
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.
i had to move this line above the first if statement so i guess it applied to all..working now..Code:Dim folderExists As Boolean
NOW i will open new thread for different problems.
thank you