Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 157
  • Last Modified:

Adding Progress Bar with Loop

I found this code in EE site and I would like to add a progress bar to this...


Private Sub ExeToTxt(ExeName As String, TxtName As String)
Me.MousePointer = vbHourglass
    Dim B As Byte
    Dim FLen As Long
    Dim I As Long
   
    Open ExeName For Binary As #1
    Open TxtName For Append As #2
   
    FLen = FileLen(ExeName)
   
    For I = 1 To FLen
        Get #1, I, B
        If Len(Hex(B)) = 2 Then
            Print #2, Hex(B);
        Else
            Print #2, "0" + Hex(B);
        End If
    Next
   
    Close #2
    Close #1
   Me.MousePointer = vbDefault
MsgBox "DONE", vbInformation
End Sub

Private Sub TxtToExe(TxtName As String, ExeName As String)
Me.MousePointer = vbHourglass
    Dim B(0 To 1) As Byte
    Dim FLen As Long
    Dim V As Byte
    Dim I As Long
   
    Open ExeName For Binary As #1
    Open TxtName For Binary As #2
   
    FLen = FileLen(TxtName)
   
    For I = 1 To FLen Step 2
        Get #2, I, B
        V = Val("&H" + Format(Chr(B(0))) + Format(Chr(B(1))))
        Put #1, , V
    Next
   
    Close #2
    Close #1
Me.MousePointer = vbDefault
MsgBox "DONE", vbInformation
End Sub
0
thaburner
Asked:
thaburner
1 Solution
 
Mark_FreeSoftwareCommented:

add a progress bar to your form (ProgressBar1), and then modify the code so it looks like this:

Private Sub ExeToTxt(ExeName As String, TxtName As String)
Me.MousePointer = vbHourglass
    Dim B As Byte
    Dim FLen As Long
    Dim I As Long
   
    Open ExeName For Binary As #1
    Open TxtName For Append As #2
   
    FLen = FileLen(ExeName)

    ProgressBar1.Min = 1
    ProgressBar1.Max = FLen
    ProgressBar1.Value = 1

    For I = 1 To FLen
        Get #1, I, B
        If Len(Hex(B)) = 2 Then
            Print #2, Hex(B);
        Else
            Print #2, "0" + Hex(B);
        End If
        ProgressBar1.Value = I
    Next
   
    Close #2
    Close #1
   Me.MousePointer = vbDefault
MsgBox "DONE", vbInformation
End Sub


Private Sub TxtToExe(TxtName As String, ExeName As String)
Me.MousePointer = vbHourglass
    Dim B(0 To 1) As Byte
    Dim FLen As Long
    Dim V As Byte
    Dim I As Long
   
    Open ExeName For Binary As #1
    Open TxtName For Binary As #2
   
    FLen = FileLen(TxtName)
 
    ProgressBar1.Min = 1
    ProgressBar1.Max = FLen
    ProgressBar1.Value = 1

    For I = 1 To FLen Step 2
        Get #2, I, B
        V = Val("&H" + Format(Chr(B(0))) + Format(Chr(B(1))))
        Put #1, , V
        ProgressBar1.Value = I
    Next
   
    Close #2
    Close #1
Me.MousePointer = vbDefault
MsgBox "DONE", vbInformation
End Sub
0
 
thaburnerAuthor Commented:
that did the trick thanks
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now