Results 1 to 5 of 5

Thread: Help with WHILE loop

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Jul 2001
    Location
    Maumelle, AR
    Posts
    624

    Help with WHILE loop

    I have a .7z file that always has problems when I try to copy the file via code. This happens with every .7z file that I have tested with. Therefore, I have written the following code to keep repeating a file copy function until the filesize of the destination file matches the size of the source file. However, I think this is getting caught in an endless loop. FYI, file MYFILE.7z already exists on both the source and the destination. The code below is a routine that is executed after the file is in both places to verify that the file actually copies successfully to the destination.

    Code:
     Public Sub Load_BackupFile()
    
            Dim Device As String
            Dim Source7z As Long
            Dim Dest7z As Long
    
            Device = Trim(frmmain.cmbDriveSelect.Text)
    
            'get the file size of the .7z file in the build directory & on the Device
            source7z = GetFileSize("C:\MYFILE.7z")
            Dest7z = GetFileSize(frmmain.cmbDriveSelect.Text & "MYFILE.7z")
    
            While Dest7z <> Source7z
    
                System.IO.File.Copy("C:\MYFILE.7z", Device & "MYFILE.7z", True)
    
            End While
    End Sub
    And here is the declared function I am using for GetFileSize:

    Code:
    Public Function GetFileSize(ByVal MyFilePath As String) As Long
            Dim MyFile As New FileInfo(MyFilePath)
            Dim FileSize As Long = MyFile.Length
            Return FileSize
        End Function
    Thanks for any help with this one.

    -Jeremy

  2. #2
    Fanatic Member Vectris's Avatar
    Join Date
    Dec 2008
    Location
    USA
    Posts
    941

    Re: Help with WHILE loop

    Have you checked to see that when you manually copy a .7z file it keeps the exact same size?
    If your problem is solved, click the Thread Tools button at the top and mark your topic as Resolved!

    If someone helped you out, click the button on their post and leave them a comment to let them know they did a good job

    __________________
    My Vb.Net CodeBank Submissions:
    Microsoft Calculator Clone
    Custom TextBox Restrictions
    Get the Text inbetween HTML Tags (or two words)

  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    Jul 2001
    Location
    Maumelle, AR
    Posts
    624

    Re: Help with WHILE loop

    Yes, the manual copy works fine. Issue is very strange.

  4. #4
    Frenzied Member Campion's Avatar
    Join Date
    Jul 2007
    Location
    UT
    Posts
    1,098

    Re: Help with WHILE loop

    Check to make sure that the end of your path contains a backslash. That is most likely your problem.

    Code:
    StrPath = frmmain.cmbDriveSelect.Text
    If right(StrPath,1) <> "\" Then
        Strpath &= "\"
    End If

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

    Re: Help with WHILE loop

    Use this to combine parts of a path
    IO.Path.Combine(drctry, filenm)

    and try this for your copy
    My.Computer.FileSystem.CopyFile(src, dst, overwrite:=True, showUI:=True, onUserCancel:=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

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