Page 1 of 2 12 LastLast
Results 1 to 40 of 47

Thread: [RESOLVED] HELP with check box

  1. #1

    Thread Starter
    Member
    Join Date
    May 2010
    Posts
    53

    Resolved [RESOLVED] HELP with check box

    I am new to VB and coding to start this off..

    I have an automated bat file that backs up select data on PC.
    example of first couple lines

    @echo off

    :: variables
    set drive=H:\
    set backupcmd=xcopy /s /c /d /e /h /i /r /k /y


    echo ### Backing Up Files...
    set folder=%date:~10,4%_%date:~4,2%_%date:~7,2%
    %backupcmd% "%USERPROFILE%\Favorites" "%drive%\%folder%\Favorites"

    this creates a dated folder and backs up the users "Favorites" if you will. then i have a list of other specific files that are backed up.

    I have created this


    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.

    I have a couple ideas but im not 100% sure on how it works, do i have to logged in a bat file then have it executed after the user is done? if so how do i do this?

    please help..

  2. #2

  3. #3

    Thread Starter
    Member
    Join Date
    May 2010
    Posts
    53

    Re: HELP with check box

    visual basic? lol

    running in debugging mode.

  4. #4

  5. #5

    Thread Starter
    Member
    Join Date
    May 2010
    Posts
    53

    Re: HELP with check box

    well i have "some code" that does what i want, its assigning it to each bottom, then creating the if then statement that i am having problems with..

    Like once i hit start i want the app to see what is selected then preform each action, like all in one.

    I will then have a status bar incorporated somehow.

    -B

  6. #6
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: HELP with check box

    What version of Visual Basic are you using?

  7. #7

    Thread Starter
    Member
    Join Date
    May 2010
    Posts
    53

    Re: HELP with check box

    2010 express

  8. #8
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: HELP with check box

    I kinda figured you were using VB.NET because that doesn't look like a VB6 and Earlier window.

    I have moved your thread over to the .NET section. Any coding help you got in the VB6 section wouldn't have worked in your program.

  9. #9

    Thread Starter
    Member
    Join Date
    May 2010
    Posts
    53

    Re: HELP with check box

    ahh sorry for the mix up and thank you.

  10. #10
    Fanatic Member
    Join Date
    Aug 2009
    Posts
    540

    Re: HELP with check box

    So you're wanting to test if a check box is checked, then run code appropriate to it's state?

    Code:
    If Checkbox1.Checked Then
    ''Do Some Work
    End If
    If Checkbox2.Checked Then
    ''Do Other Work
    End If
    For each check box you would need to check its checked state and then run the code if it meets your conditions. I would, however, test the state of the "full backup" check box first, if that one is checked then there is no need to check the others.
    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

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

    Re: HELP with check box



    Code:
    Public Class Form1
        Dim whCB As New ChkBoxTrack
    
        Private Sub Button1_Click(ByVal sender As System.Object, _
                                  ByVal e As System.EventArgs) Handles Button1.Click
    
            Label1.Text = whCB.toStringCB
    
            If whCB.IsOn(_cbCHK.allCB) Then
                'all on
            ElseIf whCB.Getb = _cbCHK.noCBchked Then
                'none checked
            Else
                If whCB.IsOn(_cbCHK.cb1) Then
                    Debug.WriteLine("1")
                End If
    
                If whCB.IsOn(_cbCHK.cb2) Then
                    Debug.WriteLine("2")
                End If
    
                If whCB.IsOn(_cbCHK.cb3) Then
                    Debug.WriteLine("3")
                End If
    
                If whCB.IsOn(_cbCHK.cb4) Then
                    Debug.WriteLine("4")
                End If
            End If
    
        End Sub
    
        Private Sub CheckBox1_CheckedChanged(ByVal sender As System.Object, _
                                             ByVal e As System.EventArgs) _
                                            Handles CheckBox1.CheckedChanged, _
                                                    CheckBox2.CheckedChanged, _
                                                    CheckBox3.CheckedChanged, _
                                                    CheckBox4.CheckedChanged
            Dim cb As CheckBox = DirectCast(sender, CheckBox)
            Select Case cb.Name
                Case "CheckBox1"
                    If cb.Checked Then whCB.SetB(_cbCHK.cb1) Else whCB.ClearB(_cbCHK.cb1)
                Case "CheckBox2"
                    If cb.Checked Then whCB.SetB(_cbCHK.cb2) Else whCB.ClearB(_cbCHK.cb2)
                Case "CheckBox3"
                    If cb.Checked Then whCB.SetB(_cbCHK.cb3) Else whCB.ClearB(_cbCHK.cb3)
                Case "CheckBox4"
                    If cb.Checked Then whCB.SetB(_cbCHK.cb4) Else whCB.ClearB(_cbCHK.cb4)
            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
    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
        allCB = cb1 Or cb2 Or cb3 Or cb4
    End Enum
    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

  12. #12

    Thread Starter
    Member
    Join Date
    May 2010
    Posts
    53

    Re: HELP with check box

    this is what i have now

    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
    
            Label1.Text = whCB.toStringCB
    
            If whCB.IsOn(_cbCHK.allCB) Then
                'all on
            ElseIf whCB.Getb = _cbCHK.noCBchked Then
                'none checked
            Else
    
            End If
            If whCB.IsOn(_cbCHK.cb1) Then
                Debug.WriteLine("1")
            End If
    
            If whCB.IsOn(_cbCHK.cb2) Then
                Debug.WriteLine("2")
            End If
    
            If whCB.IsOn(_cbCHK.cb3) Then
                Debug.WriteLine("3")
            End If
    
            If whCB.IsOn(_cbCHK.cb4) Then
                Debug.WriteLine("4")
            End If
    
            If whCB.IsOn(_cbCHK.cb5) Then
                Debug.WriteLine("5")
            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
    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
    added another button, now i see that what buttons are selected are displayed in the label.
    I now need to add functions to each one of the "cb1, 2, 3, ext" then be able to run them all while selecting start.

    can anyone lend another helping hand?
    Each one of the check boxes is going to be pointed to a select location on the users computer.

    please help

    -Brandon
    Last edited by littlejob; May 27th, 2010 at 12:08 PM.

  13. #13

    Thread Starter
    Member
    Join Date
    May 2010
    Posts
    53

    Re: HELP with check box

    anyone have any ideas?
    Last edited by littlejob; May 27th, 2010 at 12:08 PM.

  14. #14

    Thread Starter
    Member
    Join Date
    May 2010
    Posts
    53

    Re: HELP with check box

    UPDATE

    i found this on another forum
    HTML Code:
    If Checkm.Value = vbChecked Then
         FileCopy "C:\POS\ZDEFLTS.BTR", "C:\BACKUP\MONDAY\ZDEFLTS.BTR"
    End If
    End Sub
    not sure what is the variable, or the button name, and how do i make it apply to my code? im a little stumped on where exactly to put this.

    -Brandon

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

    Re: HELP with check box

    I started this for you, but you need to finish it. Just take a look at the way that I did things. It should give you a good head-start.

    vb Code:
    1. Public Class Form1
    2.  
    3.     Private Sub BackupButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BackupButton.Click
    4.         '
    5.         ' Test if the My Documents Checkbox is true, if it is copy all the files
    6.         ' You should use a variable in the GetFiles method.
    7.         '
    8.         If MyDocumentsCheckbox.Checked = True Then
    9.             For Each file As String In IO.Directory.GetFiles("path to user's 'My Documents' folder or variable")
    10.                 My.Computer.FileSystem.CopyFile(file, "H:\MyDocuments", False)
    11.             Next
    12.         End If
    13.  
    14.         '
    15.         ' Check to see if the desktop checkbox is checked or not. If it is copy the
    16.         ' the files from the desktop to some folder on the h:\
    17.         '
    18.         If DesktopCheckbox.Checked = True Then
    19.             For Each DesktopItem As String In IO.Directory.GetFiles("path to the user's desktop folder")
    20.                 My.Computer.FileSystem.CopyFile(DesktopItem, "H:\DesktopFiles", False)
    21.             Next
    22.         End If
    23.  
    24.         ' so and so forth, you may want to think about a way to compress the files into one archive.
    25.         ' I run a backup program and I use SharpZipLib to put everything in a ZIP archive. It will also
    26.         ' gzip and other compression formats. Just google it and you will get some information. If you need
    27.         ' more help, please let us know.
    28.     End Sub
    29. End Class
    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

  16. #16

    Thread Starter
    Member
    Join Date
    May 2010
    Posts
    53

    Re: HELP with check box

    thank you A LOT. i ahve been trying to do this for a while.

    I am running into an error thogh when trying to execute the app.
    "IOException was unhandled."

    "The file 'H:\test\favorites' already exists."

    when in fact it does not.. then it crashes out..i do see that the folder test was created but no favorites.

    Code:
    Private Sub Button1_Click(ByVal sender As System.Object, _
                                  ByVal e As System.EventArgs) Handles start.Click
    
            If mydocuments.Checked = True Then
                For Each file As String In IO.Directory.GetFiles("C:\Documents and Settings\godboubs\Favorites")
                    My.Computer.FileSystem.CopyFile(file, "H:\test\favorites", False)
                Next
            End If
    
        End Sub
    and yes...i know that the mydocuments chkbox is backing up favorites..just using as an example.

    thanks again

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

    Re: HELP with check box

    Code:
    My.Computer.FileSystem.CopyFile("SRC", "DST", True)
    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

  18. #18
    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
    thank you A LOT. i ahve been trying to do this for a while.

    I am running into an error thogh when trying to execute the app.
    "IOException was unhandled."

    "The file 'H:\test\favorites' already exists."

    when in fact it does not.. then it crashes out..i do see that the folder test was created but no favorites.

    Code:
    Private Sub Button1_Click(ByVal sender As System.Object, _
                                  ByVal e As System.EventArgs) Handles start.Click
    
            If mydocuments.Checked = True Then
                For Each file As String In IO.Directory.GetFiles("C:\Documents and Settings\godboubs\Favorites")
                    My.Computer.FileSystem.CopyFile(file, "H:\test\favorites", False)
                Next
            End If
    
        End Sub
    and yes...i know that the mydocuments chkbox is backing up favorites..just using as an example.

    thanks again
    Change this line:

    .net Code:
    1. For Each file As String In IO.Directory.GetFiles("C:\Documents and Settings\godboubs\Favorites")

    To:

    .net Code:
    1. For Each file As String In IO.Directory.GetFiles("C:\Documents and Settings\godboubs\Favorites\")
    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

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

    Re: HELP with check box

    Quote Originally Posted by mbutler755 View Post
    Change this line:

    .net Code:
    1. For Each file As String In IO.Directory.GetFiles("C:\Documents and Settings\godboubs\Favorites")

    To:

    .net Code:
    1. For Each file As String In IO.Directory.GetFiles("C:\Documents and Settings\godboubs\Favorites\")
    Use this one instead

    .net Code:
    1. Public Class Form1
    2.  
    3.     Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    4.         If CheckBox1.Checked = True Then
    5.             '
    6.             ' Check to see if the directory exists. If it does not, create it
    7.             '
    8.             Dim folderExists As Boolean
    9.             folderExists = My.Computer.FileSystem.DirectoryExists("p:\1050")
    10.             If folderExists = False Then
    11.                 My.Computer.FileSystem.CreateDirectory(folderExists)
    12.             End If
    13.  
    14.             '
    15.             ' Parse out the path from the filename and copy the files.
    16.             '
    17.             For Each DesktopFile As String In IO.Directory.GetFiles("c:\1050", "*.*")
    18.                 My.Computer.FileSystem.CopyFile(DesktopFile, "p:\1050\" & My.Computer.FileSystem.GetName(DesktopFile))
    19.             Next
    20.  
    21.             '
    22.             ' I tested this one and it works perfectly
    23.             '
    24.         End If
    25.     End Sub
    26. End Class
    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

  20. #20

    Thread Starter
    Member
    Join Date
    May 2010
    Posts
    53

    Re: HELP with check box

    Did what you tried matt,

    ArgumentException was unhandled
    "The given file path ends with a directory separator character.
    Parameter name: destinationFileName"

    hmm..

    and with this code
    Code:
    My.Computer.FileSystem.CopyFile("SRC", "DST", True)
    does this copy folders or just specific files?

    -Brandon

  21. #21
    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 littlejob View Post
    Did what you tried matt,

    ArgumentException was unhandled
    "The given file path ends with a directory separator character.
    Parameter name: destinationFileName"

    hmm..

    and with this code
    Code:
    My.Computer.FileSystem.CopyFile("SRC", "DST", True)
    does this copy folders or just specific files?

    -Brandon
    hmmmmmm.
    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

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

    Re: HELP with check box

    You can also change the method to CopyDirectory and copy multiple directories. Take a look at the method and let me know if you need help.
    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

  23. #23

    Thread Starter
    Member
    Join Date
    May 2010
    Posts
    53

    Re: HELP with check box

    its been a long day...

    the method you posted earlier worked the "use this one instead"

    however. If you run the backup again when the file is already there it error-ed out.

    Forgetting this, i changed to directory? i think below

    Code:
    Private Sub Button1_Click(ByVal sender As System.Object, _
                                  ByVal e As System.EventArgs) Handles start.Click
    
            '
            ' Check to see if the directory exists. If it does not, create it
            '
            Dim folderExists As Boolean
            folderExists = My.Computer.FileSystem.DirectoryExists("h:\test\favorites")
            If folderExists = False Then
                My.Computer.FileSystem.CreateDirectory(folderExists)
            End If
    
            '
            ' Parse out the path from the filename and copy the files.
            '
            For Each DesktopFile As String In IO.Directory.GetFiles("C:\Documents and Settings\godboubs\Favorites", "*.*")
                My.Computer.FileSystem.CopyDirectory(DesktopFile, "h:\test\favorites" & My.Computer.FileSystem.GetName(DesktopFile))
            Next
    
            '
            ' I tested this one and it works perfectly
            '
    
    
        End Sub
    says it cannot find file.

    another question 2
    "("C:\Documents and Settings\godboubs\Favorites", "*.*")"

    does this mean pull all file types? not folder? does this have to be changed as well?

    -Brandon

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

    Re: HELP with check box

    In this first line of your program type

    Option Strict On

    Code:
            Dim folderExists As Boolean
            folderExists = My.Computer.FileSystem.DirectoryExists("h:\test\favorites")
            If folderExists = False Then
                My.Computer.FileSystem.CreateDirectory(folderExists) '<<<<< create the true or false directory
    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

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

    Re: HELP with check box

    Again, you are missing the last slash before the GetNames method.

    Change this:

    vb Code:
    1. For Each DesktopFile As String In IO.Directory.GetFiles("C:\Documents and Settings\godboubs\Favorites", "*.*")
    2.             My.Computer.FileSystem.CopyDirectory(DesktopFile, "h:\test\favorites" & My.Computer.FileSystem.GetName(DesktopFile))
    3.         Next

    To This:
    vb Code:
    1. For Each DesktopFile As String In IO.Directory.GetFiles("C:\Documents and Settings\godboubs\Favorites", "*.*")
    2.             My.Computer.FileSystem.CopyDirectory(DesktopFile, "h:\test\favorites\" & My.Computer.FileSystem.GetName(DesktopFile))
    3.         Next
    Last edited by mbutler755; May 27th, 2010 at 03:25 PM. Reason: bold was jacked up
    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

  26. #26

    Thread Starter
    Member
    Join Date
    May 2010
    Posts
    53

    Re: HELP with check box

    You guys reply really fast, lol

    I too noticed this and it did not change anything.

    "Could not find directory 'C:\Documents and Settings\godboubs\Favorites\Desktop.ini'."

    HTML Code:
    My.Computer.FileSystem.CopyDirectory(DesktopFile, "h:\test\favorites\" & My.Computer.FileSystem.GetName(DesktopFile))
    points here ^

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

    Re: HELP with check box

    You have to change the For Each line also. You are going to be looking for directories instead of files.

    vb Code:
    1. For Each folder As String In IO.Directory.GetDirectories("this is the source")
    2.             My.Computer.FileSystem.CopyDirectory(folder, "h:\whatever\" & My.Computer.FileSystem.GetName(folder))
    3.         Next
    4.     End Sub
    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

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

    Re: HELP with check box

    I have a backup program. It basically creates a process that is

    xcopy sourcedir destdir /C/Y/E/H/R/I
    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

  29. #29

    Thread Starter
    Member
    Join Date
    May 2010
    Posts
    53

    Re: HELP with check box

    OK day 2 begins...

    Code:
    Private Sub Button1_Click(ByVal sender As System.Object, _
                                  ByVal e As System.EventArgs) Handles start.Click
    
            '
            ' Check to see if the directory exists. If it does not, create it
            '
            Dim folderExists As Boolean
            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.
            '
            For Each folder As String In IO.Directory.GetDirectories("C:\Documents and Settings\godboubs\Favorites", "*.*")
                My.Computer.FileSystem.CopyDirectory(folder, "h:\test\favorites\" & My.Computer.FileSystem.GetName(folder))
            Next
    
    
        End Sub
    FIRST
    Got this working, thanks again for your help however i ran across a couple different things. First the contents of "Favorites in this case (all the URL's) do not get copied, just the sub folders in "Favorites" then the links inside those sub folders.

    SECOND
    When i run the app a second time after it partially backs up the folder i get an IOException error, "could not complete operation on some files and directories. See the data property of the exception for more details"

    THIRD (UPDATE) - figured this part out...

    My application looks like this, the code is ran after i click button, i need for it to determine what is selected above first...then run the script according to the users selection.

    Code:
    If MyDocumentsCheckbox.Checked = True Then
    FOURTH
    I want to back up the current user logged in files. I know in a batch file it was something along the line of "&#37;USERPROFILE%\Favorites"
    not sure how to do in this new greatness im learning

    Thanks
    Last edited by littlejob; May 28th, 2010 at 08:13 AM.

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

    Re: HELP with check box

    Please post your code for the favorites. You will probably need to run 2 For Each loops. One loop for the folders & and sub-directory files and the other just for files.
    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

  31. #31

    Thread Starter
    Member
    Join Date
    May 2010
    Posts
    53

    Re: HELP with check box

    Quote Originally Posted by mbutler755 View Post
    Please post your code for the favorites. You will probably need to run 2 For Each loops. One loop for the folders & and sub-directory files and the other just for files.
    Code:
    If mydocuments.Checked = True Then
                '
                ' Check to see if the directory exists. If it does not, create it
                '
                Dim folderExists As Boolean
                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.
                '
                For Each folder As String In IO.Directory.GetDirectories("C:\Documents and Settings\godboubs\Favorites", "*.*")
                    My.Computer.FileSystem.CopyDirectory(folder, "h:\test\favorites\" & My.Computer.FileSystem.GetName(folder))
                Next
            End If
    and yes i know i have it coded for the my docs chk box...

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

    Re: HELP with check box

    Underneath your folder For Each, you will need another one to copy the files.

    vb Code:
    1. For Each FavFile as String in IO.Directory.GetFiles("C:\Documents and Settings\godboubs\Favorites","*.*")
    2.      My.Computer.FileSystem.CopyFile(FavFile,"H:\test\favorites\" & My.Computer.FileSystem.GetName(FavFile))
    3. Next
    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

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

    Re: HELP with check box

    Code:
            'two test folders
            Dim fromF As String = My.Computer.FileSystem.SpecialDirectories.Desktop & "\Test1"
            Dim toF As String = My.Computer.FileSystem.SpecialDirectories.Desktop & "\Test2"
    
            Dim sw1s As String = " /C/Y/E/H/R/I"
            'define command
            Dim theCMD As String = "xcopy"
            'define comand arguments
            Dim theARG As String = """" & fromF & """" & " " & """" & toF & """" & sw1s
            'define process and info for it
            Dim proc As New Process()
            Dim procSI As New ProcessStartInfo()
            'set info for command
            procSI.FileName = theCMD
            procSI.Arguments = theARG
            procSI.CreateNoWindow = False
            procSI.UseShellExecute = True
            proc.StartInfo = procSI
            proc.Start()
    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

  34. #34

    Thread Starter
    Member
    Join Date
    May 2010
    Posts
    53

    Re: HELP with check box

    Quote Originally Posted by mbutler755 View Post
    Underneath your folder For Each, you will need another one to copy the files.

    vb Code:
    1. For Each FavFile as String in IO.Directory.GetFiles("C:\Documents and Settings\godboubs\Favorites","*.*")
    2.      My.Computer.FileSystem.CopyFile(FavFile,"H:\test\favorites\" & My.Computer.FileSystem.GetName(FavFile))
    3. Next
    a little confused, what you have looks the same as what i have? another question what does that "FavFile" represent?

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

    Re: HELP with check box

    It is different. The first For Each loop is using the GetDirectories method. The second one, that I just wrote is using the GetFiles method. One For Each loop is getting files, the other is getting directories and the directory's sub-files.

    FavFile is just a string representation of each file within the Favorites folder.

    A much easier way of doing this would be to copy the Favorites directory in its entirety. This would be much better than copying the directories within the Favorites directory and then the files. If you want to copy everything anyways, you might as well just copy the top line directory. You can accomplish this by using the My.Computer.FileSystem.CopyDirectory method.
    Last edited by mbutler755; May 28th, 2010 at 09:19 AM.
    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

  36. #36
    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 dbasnett View Post
    Code:
            'two test folders
            Dim fromF As String = My.Computer.FileSystem.SpecialDirectories.Desktop & "\Test1"
            Dim toF As String = My.Computer.FileSystem.SpecialDirectories.Desktop & "\Test2"
    
            Dim sw1s As String = " /C/Y/E/H/R/I"
            'define command
            Dim theCMD As String = "xcopy"
            'define comand arguments
            Dim theARG As String = """" & fromF & """" & " " & """" & toF & """" & sw1s
            'define process and info for it
            Dim proc As New Process()
            Dim procSI As New ProcessStartInfo()
            'set info for command
            procSI.FileName = theCMD
            procSI.Arguments = theARG
            procSI.CreateNoWindow = False
            procSI.UseShellExecute = True
            proc.StartInfo = procSI
            proc.Start()
    When I did my backup program I started off just like you are. Build a directory list, and copy each directory to the backup location. When I thought I was done, I wasn't. I finally implemented the xcopy and have been happy ever since (I don't remember what error sent me over the edge).

    So, the above code can be implemented easily as a sub that takes two folders as args. Just remember it is here.
    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

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

    Re: HELP with check box

    This works perfectly to copy ALL of the favorites:

    vb Code:
    1. Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    2.         If Favorites.Checked = True Then
    3.  
    4.             Dim folderExists As Boolean
    5.             folderExists = My.Computer.FileSystem.DirectoryExists("h:\favorites")
    6.             If folderExists = False Then
    7.                 My.Computer.FileSystem.CreateDirectory(folderExists)
    8.             End If
    9.  
    10.  
    11.             Try
    12.                 My.Computer.FileSystem.CopyDirectory("c:\documents and settings\godboubs\favorites", "h:\favorites", True)
    13.             Catch ex As ApplicationException
    14.                 MsgBox(ex.Message, MsgBoxStyle.Exclamation)
    15.             End Try
    16.  
    17.         End If
    18.     End Sub
    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

  38. #38
    Fanatic Member
    Join Date
    Aug 2009
    Posts
    540

    Re: HELP with check box

    *edit too slow!*
    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

  39. #39

    Thread Starter
    Member
    Join Date
    May 2010
    Posts
    53

    Re: HELP with check box

    i get an IO exception error stating that the file allready exists..but it does not exits, nor does it create the file.

  40. #40
    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
    i get an IO exception error stating that the file allready exists..but it does not exits, nor does it create the file.
    Post the code and the error.

    Are you using the code from post #37?
    Last edited by mbutler755; May 28th, 2010 at 10:09 AM. Reason: added info
    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

Page 1 of 2 12 LastLast

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