Get the size of a file selected in a FileListBox
By: Greg Karner Date: 07/10/1998

This is an easy way to get the file size of any file a user might select. Lets assume you have a form with a directory list box called mydir and a file list box named myfile. The user can scroll to any directoy on their hard drive, select a file from the file list box and the program will tell them the size of that file. Heres the code:

oldfile = mydir & "\" & myfile
oldsize = FileLen(oldfile)

Now you can create a lable on your form that will display
the size of the file. Try this:

lblFileSize.Caption = "The file is " & _
oldsize & " bytes in size."

Of course, if you want the lable to display a large file
with commas in the correct place, you will have to format
oldsize. Do it like this:

lblFileSize.Caption = "The file is " & _
Format(oldsize, "#,###,##0") & " bytes in size."

Click Here!

Visual Basic Programming Zone is a website by Lorenzo Dalla Vecchia.
To contact the Webmaster, click here.
Hosted by InWind: