Results 1 to 4 of 4

Thread: Size of File

  1. #1

    Thread Starter
    Member
    Join Date
    Jun 2000
    Posts
    55
    how do i put the number of bytes a file consists into an integer?
    and how do i put a value of a char or the value of all of the bytes in a file into an integer?

    thanks

  2. #2
    Member
    Join Date
    Jun 2000
    Location
    Manchester, UK
    Posts
    50

    Cool

    The FileLen function returns the number of bytes in a file, e.g.:

    num = FileLen("c:\readme.txt")

  3. #3

    Thread Starter
    Member
    Join Date
    Jun 2000
    Posts
    55
    how do i get the ascii value of a char?

  4. #4
    Lively Member
    Join Date
    Apr 2000
    Posts
    110
    Right then. To get the length of a file in bytes, you can use the LEN function. It is probably better for you to use a Long data type than an integer. It depends on the size of the file you want to know the size of. For example, if you were dealing with an .exe or an mp3, you would probably use a long, as it's length would probably exceed the integers range. Always go for the long if you're not sure.

    Code:
    'Get the length of a file in bytes.
    Dim lngData As Long
    
    Open "C:\MyFile.txt" For Binary As #1
        lngData = LOF(1)
    Close #1
    
    MsgBox " The length of the file is: " & lngData & " bytes."
    To get the ascii value of a character, use the following code:

    Code:
    'Get the asci code for a character.
    Dim strChar As String * 1 '1 character long.
    Dim intAsc As Integer
    
    strChar = "R"
    intAsc = Asc(strChar)
    MsgBox "The Asc number for the character 'R' is " & intAsc & ""
    Hope this helps.

    Later(z)

    REM


    "Innovate, don't immitate."

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