PROGRESSBAR PROJECT

Thanks to Im_[B]OReD for his coding on the use of  file transfer using binary copy. I made some changes and additions to the codes to ensure the file transfer is usable and the percentage of the progressbar is visible while the data tranfer is going on.

The original coding i get from the web is without the Get #1, ,CopyByteForByte. I found the content of the copied file is not the same asthe original one without this line and the original coding was without the do events. I inserted the do events to make sure that I can see the label3.caption (percentage) while the transfer is taking place.

Once again I would like to thank IM.

 

By : 9M2AR - ABDUL RAHMAN RAOF

.Dim srcfile, dstfile, nn, yy
' By: Im_[B]0ReD

Function CopyFile(srcfile As String, dstfile As String)
'this copies a file byte-for-byte
'or you could just use good old FileCopy
' :-)
On Error Resume Next 'If we Get an error, keep going
Dim Copy As Long, CopyByteForByte As Byte 'the variables
Open srcfile For Binary Access Read As #1 'open the destination file so we can write To it
Open dstfile For Binary Access Write As #2 'open the source file so we can read from it

Do While DoEvents
If nn = ProgressBar1.Max Then Exit Do 'Copy The SourceFile Byte-For-Byte
Get #1, , CopyByteForByte
Put #2, , CopyByteForByte 'Put the byte In the destination file
nn = nn + 1 'ProgressBar1.Max / 1000000
Label3.Caption = Str(Int(nn / ProgressBar1.Max * 100)) + "%"
If nn < ProgressBar1.Max Then ProgressBar1.Value = nn
Loop 'stop the Loop
Close #1
Close #2
End Function


Private Sub Command1_Click()
On Error Resume Next
ProgressBar1.Min = 0: ProgressBar1.Value = 0: nn = 0
ProgressBar1.Max = FileLen(Text1)
scrfile = Text1
dstfile = Text2
Kill Text2
CopyFile Text1, Text2
ProgressBar1.Value = ProgressBar1.Max
Label3.Caption = "Selesai" ' done
End Sub

Private Sub Command1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
Label3.Caption = "Sedang menyalin" 'means copying
End Sub

Private Sub Command2_Click()
menu.Show
Unload Me
Set pbsalin1 = Nothing
End Sub

Private Sub Form_Load()
Me.Top = (Screen.Height - Me.Height) / 2
Me.Left = (Screen.Width - Me.Width) / 2
End Sub