Results 1 to 4 of 4

Thread: Working with buffers

  1. #1

    Thread Starter
    Hyperactive Member Troy Lundin's Avatar
    Join Date
    May 2006
    Posts
    489

    Working with buffers

    I am trying to store a file's data into a byte array and display it in a textbox.

    I tried this:

    VB Code:
    1. Option Explicit
    2. Private b() As Byte
    3. Private Sub Command1_Click()
    4. Open "c:\7za.exe" For Binary As #1
    5. Get #1, , b
    6. Text1.Text = b
    7. Close #1
    8. End Sub


    when i click the button text1 becomes empty. Note that c:\7za.exe is a valid file.
    Prefix has no suffix, but suffix has a prefix.

  2. #2
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: Working with buffers

    Texboxes can't display the full range of ascii characters (most notably chr(0) ), which is what binary files can contain.

    You can either remove the "invalid" characters from b before displaying it, or display it in way that can show all the characters.

  3. #3

    Thread Starter
    Hyperactive Member Troy Lundin's Avatar
    Join Date
    May 2006
    Posts
    489

    Re: Working with buffers

    Ok, then how would I get the length af an array.
    I tried Len(b) but it didn't work. Mind you I am still learning the methods of vb6 as they differ from .net
    Prefix has no suffix, but suffix has a prefix.

  4. #4
    VB6, XHTML & CSS hobbyist Merri's Avatar
    Join Date
    Oct 2002
    Location
    Finland
    Posts
    6,654

    Re: Working with buffers

    UBound(b) would return the last index of an array. Since arrays often start from index 0 (and it is a good thing if they always do: other types of starting indexes are slow in VB6) you need to add one to get the total number of items.

    To check if an array is empty, see ArrayInit function I've provided in this post at the FAQ forum.

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