Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Managing a ProgressBar during File Upload

Status
Not open for further replies.

ufobaby

MIS
Sep 25, 2001
238
0
0
US
hi all,

I want to show a progress bar which will display exact bytes/lines from a file which is being uploaded.

I am using FileSystemObject to upload a delimited file to MS Access Database. How do i determine the total records/total size before hand, and also the number of records uploaded or the total bytes uploaded.

Any suggestions... this is a little URGENT

Many Thanks
Cheers !!!
Niraj >:):O>
 
Niraj,


You can cut & paste the following code into a test project. It uses the File object to find the total size of the target file, This can be the max value of the progress bar. As you read through you target file just increment the progress bar value by the length of the text read.

Andy.


Private Sub Form_Load()
Dim objFSO As Scripting.FileSystemObject
Dim objFile As Scripting.File
Dim objTS As Scripting.TextStream
Dim strText As String

'Create the file system object
Set objFSO = New Scripting.FileSystemObject

'Find the size of the file
Set objFile = objFSO.GetFile("C:\WinZip.log")
Debug.Print objFile.Size

'Now we can read the file, line by line
Set objTS = objFSO.OpenTextFile("C:\WinZip.log", ForReading)
Do While Not (objTS.AtEndOfStream)
strText = objTS.ReadLine
Debug.Print strText, Len(strText)
Loop
objTS.Close

'Tidy up our objects
Set objTS = Nothing
Set objFile = Nothing
Set objFSO = Nothing
End Sub
 
Andy, Thanks a ton

But there is a slight problem with this. The ProgressBar completes 100% but all the bytes are not transfered. Actually there is a difference between the Total Size and the Size/Lenght read during the upload. Can't figure out why.

Also tired using the FileLen() function to determine the size and then the LenB() function and converting it to Unicode.

Ex -

Set FSO = CreateObject("scripting.filesystemobject")

Set ts = FSO.OpenTextFile(Path1)
LenFl = FileLen(Path1)
pb1.Max = LenFl
pb1.Min = 0

ctr = 0

Do While ts.AtEndOfStream = False
LineRd = ts.ReadLine
LenLine = LenB(StrConv(LineRd, vbFromUnicode))
ctr = ctr + LenLine
pb1.Value = ctr
Loop

Conversion to Unicode reduces the difference between the two but it is still there. The PBar stops at 98-97 %. i.e the actual size after reading through the file is less than the actual size returned by the FileLen() or objFso.Size

Any Suggestions ???

Cheers !!!
Niraj >:):O>
 
Are your lines all about 100 bytes long...
Each line ends in LF or more likely CR+LF in the file
They don't in teh string.
[tt]
ctr = ctr + LenLine + 2
[/tt]


Wil Mead
wmead@optonline.net

 
Thanx a million... WilMead

This works exactly like i wanted. But can u please explain this with a example elobrated. I am kind of confused with string and line. why only + 2 ??? Even about the Unicode conversion, i read in some forum but did not understand much. If you could explain or redirect me to some site explaining this.

Also on what basis does the FileLen() or Size function calculate the size.

Thanx a million once again.
Cheers!!!
Niraj >:):O>
 
Hi AndyDuke,

I'm looking for somewhat the same solution concerning ProgresBar. I however is using the copy features of FSO to copy a new file. My problem is how to provide a value to a progress bar during the copying itself.

I tried timer control, but due to intensiveness of the operation the progress bar does not update.

Any idea on how can I copy a file using FSO then reflect the copied byte to the ProgressBar?
 
mhm,

Sorry for the delay, I've just returned from holiday.
I don't think you can use a progress bar with teh FSO object because there is no feedback from the copy method in the FSO object. In applications like Windows Explorer they use a form with an AVI (animation) to show that the copy is in progress.

Search you PC for the FileCopy.avi file. You can add this to a form using the animation control (in the MSCOMCT2.OCX file) and display the form when copying the file. When the copy is complete remove the form with the avi and display a 'complete' message.

I've used this method a number of times when you cannot determine the length of time that the task will take to complete.

Hope this helps.

Andy.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top