Results 1 to 4 of 4

Thread: Error on binary file read? FIXED

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Jan 2001
    Location
    Newbury, UK
    Posts
    1,878

    Error on binary file read? FIXED

    I have a very simple program:
    VB Code:
    1. Private Sub Command1_Click()
    2.     Open "c:\temp\my.txt" For Binary Access Read As #1
    3.     sDATA = Space$(LOF(1))
    4.     Get #1, , sDATA
    5.     MsgBox sDATA
    6. End Sub
    The file exists OK.
    LOF(1) shows a length of 50.
    But on the GET line, I receive an error of:
    " Run time error 458
    Variable uses an automation type not supported in Visual Basic "

    Any ideas why?
    Last edited by JordanChris; Nov 20th, 2002 at 09:48 AM.

  2. #2
    Retired VBF Adm1nistrator plenderj's Avatar
    Join Date
    Jan 2001
    Location
    Dublin, Ireland
    Posts
    10,359
    Just try this

    VB Code:
    1. Open "c:\someFile.txt" For Binary As #1
    2.     Dim strBuff As String: strBuff = Space(Lof(1))
    3.     Get #1, , strBuff
    4. Close #1

    strBuff would then contain the contents of the file
    Microsoft MVP : Visual Developer - Visual Basic [2004-2005]

  3. #3

    Thread Starter
    Frenzied Member
    Join Date
    Jan 2001
    Location
    Newbury, UK
    Posts
    1,878
    THANKS.

    I didn't have the CLOSE, so I wonder if I had previously opened it and it didn't like doing so again?

  4. #4
    I wonder how many charact
    Join Date
    Feb 2001
    Location
    Savage, MN, USA
    Posts
    3,704
    It wasn't about Closing... You needed to declare sData explicity... as plenderj did... otherwise, the compiler uses a variable type that it thinks it should, and obviously it picked the wrong type for the job..

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