Results 1 to 13 of 13

Thread: Opening an EXE File into a Textbox, Just like opening a text file???

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 1999
    Location
    Leeds, UK
    Posts
    287

    Post

    Hi,

    I would like to open up an EXE file into a textbox using this code:

    Open "C:\Ascii.exe" For Input As #1
    text1.Text = Input(LOF(1), 1)
    Close #1

    When I try that I get a message "Bad file number or number". What does that mean.

    Thanks

  2. #2
    Junior Member
    Join Date
    Nov 1999
    Posts
    26

    Post

    I think it has to be opened in Binary mode, but I cant remember the command to get data from a file opened in binary.

    Hope this helps.

    ------------------
    Quadrex
    webmaster@quadrex.f9.co.uk
    Quadrex Programming


  3. #3
    PowerPoster
    Join Date
    Jul 1999
    Posts
    5,923

    Post

    Insert "Binary" between "For" and "Input" on the first line.
    It says bad file number, this suggests to me it is the file number playing up here. I notice you use #1 as the file number. Instead, declare a variable (like Dim FileNumber As Variant) and assign it the FreeFile function (FileNumber = FreeFile). Then replace all the #1 you have typed with #FileNumber.

    You should now have the following:-

    Dim FileNumber As Variant

    FileNumber = FreeFile

    Open "C:\Ascii.exe" For Binary Input As #FileNumber
    Text1.Text = Input(LOF(1), 1)
    Close #FileNumber

    That should do the trick.

    Regards,

    ------------------
    - Chris
    chris.kilhams@btinternet.com
    If it ain't broke - don't fix it

  4. #4
    Guest

    Post

    Humm? Work does it not! No? (My best Yoda impression, Sorry.)

    ------------------
    Matthew Ralston
    E-Mail: m.ralston@mediavault.co.uk
    ICQ:31422892
    Web Sites:The Blue Link My Home Page



    [This message has been edited by matthewralston (edited 11-29-1999).]

  5. #5
    PowerPoster
    Join Date
    Jul 1999
    Posts
    5,923

    Post

    what bit doesn't work mr. yoda, supreme jedi commander?

    I'm only suggesting it's the file number that's being a problem...I didn't check the rest of Rino's code.

    Regards,

    ------------------
    - Chris
    chris.kilhams@btinternet.com
    If it ain't broke - don't fix it


    [This message has been edited by chrisjk (edited 11-29-1999).]

  6. #6
    Lively Member
    Join Date
    Jun 1999
    Location
    Ireland
    Posts
    96

    Post

    Sorry, my mistake, bad post here, I just deleted it.

    I checked again, and it works fine for me when I use "binary" instead of "input"

    Steve.



    [This message has been edited by SteveS (edited 11-30-1999).]

  7. #7
    Hyperactive Member
    Join Date
    Oct 1999
    Posts
    309

    Post

    I get an error in design mode:
    Code:
    Open "C:\Ascii.exe" For Binary Input As #FileNumber
    "Input" is selected...

    The error is :
    Compile error
    Expected: As


  8. #8
    Frenzied Member Mark Sreeves's Avatar
    Join Date
    Nov 1999
    Location
    UK
    Posts
    1,845

    Post

    Do This:
    Code:
    Dim fnum As Long
    Dim strtemp As String
    fnum = FreeFile
    Open "c:\Ascii.exe" For Binary As fnum
    strtemp = Space(LOF(fnum))
    
    Get fnum, , strtemp
    Close fnum
    the contents of the file are now in strTemp

    do waht you want with it!

    ------------------
    Mark Sreeves
    Analyst Programmer

    Mark.Sreeves@Softlab.co.uk
    A BMW Group Company

  9. #9
    Member
    Join Date
    Jan 1999
    Location
    London, UK
    Posts
    58

    Post

    If you want to READ BINARY you have to insert "Access", i.e.

    ...
    Open strFileName For Binary Access Read As #FileNum
    ...

    AC

  10. #10
    Hyperactive Member
    Join Date
    Oct 1999
    Posts
    309

    Post

    Hehehe.... All I seem to get in the crappy textbox is :

    MZ

  11. #11
    Hyperactive Member
    Join Date
    Jan 1999
    Location
    Rotterdam, Netherlands
    Posts
    386

    Post

    I coud have told you that's all you get.. since a textbox can't really display the binary data (open an exe with notepad and you see what I mean.....)
    Why do you want to display the contents of an exe anyway?

  12. #12
    Hyperactive Member
    Join Date
    Oct 1999
    Posts
    309

    Post

    Well, it was officially started by Rino_2, I can't give you his motivation....

    But sometimes it is handy to edit binary files like you would in a hex-editor....

    I've been looking for clean vb-source of a plain hex-editor but haven't realy found one yet.....

    This is why I was interested..... Although this post has nothing to do with hex-editing, it is about viewing binaries...

    That's all

    [This message has been edited by Inhumanoid (edited 11-30-1999).]

  13. #13

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 1999
    Location
    Leeds, UK
    Posts
    287

    Post

    Thank you all, GREAT HELP!!!!!!

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