Results 1 to 18 of 18

Thread: Opening Files

  1. #1
    Guest

    Angry

    I need to know how i can possibly open non text files (such as 'exe', 'doc', 'jpg', etc...) into a string with vb. The only way i was able to do it was using 'input' one character at a time, but i do not have 17 hours to let this program run. is there a way that i can just grab the entire file (or at least large chunks of it) and dump it into a string?

  2. #2
    Fanatic Member
    Join Date
    Mar 2000
    Location
    That posh bit of England known as Buckinghamshire
    Posts
    658
    Code:
    Dim strInput as String
    
    open "myjpg.jpg" for input as #1
    
    strInput = Input(LOF(1), #1)
    Iain, thats with an i by the way!

  3. #3
    Guest

    Does not work( AAARGHHHH!!!)

    I've already tried that, and I get this error:
    Runtime error '62':
    Input past end of file
    Is there a way to avoid this?

  4. #4
    Fanatic Member
    Join Date
    Feb 2000
    Location
    Japan
    Posts
    840
    It's faster to load the file into a byte array then use StrConv()

    Also means you have the bytes if you need them

    Even for text files, you can open many megs a second, in a test I did, my vb app opened a 3mb text file at the same speed winnt notepad did!
    Paul Dwyer
    Network Engineer
    Aussie In Tokyo

    Using Powerbasic 6 & VB6 SP4 (Please also add your VB Version to your signature!)

  5. #5
    Fanatic Member
    Join Date
    Feb 2000
    Location
    Japan
    Posts
    840

    Re: Does not work( AAARGHHHH!!!)

    Originally posted by spetnik
    I've already tried that, and I get this error:
    Runtime error '62':
    Input past end of file
    Is there a way to avoid this?
    Does the file have double byte characters in it? (chinese, Japanese, Korean etc)

    Input reads characters and LOF reads bytes so it will read past the end! use the byte array!
    Paul Dwyer
    Network Engineer
    Aussie In Tokyo

    Using Powerbasic 6 & VB6 SP4 (Please also add your VB Version to your signature!)

  6. #6
    Guest

    byte array?

    How do i use byte-array (im unfamiliar w/ this term)

  7. #7
    Fanatic Member
    Join Date
    Mar 2000
    Location
    That posh bit of England known as Buckinghamshire
    Posts
    658
    I'd do as he says, he seems to know what he is talking about, while i just blag my way through programming.
    Iain, thats with an i by the way!

  8. #8
    Fanatic Member
    Join Date
    Feb 2000
    Location
    Japan
    Posts
    840

    Thumbs up

    Thanks lain17, For that compliment you get code!

    Chuck this on a form with a button, just change the file name

    Code:
    Private Sub Command1_Click()
    
        Dim Bytes() As Byte
        Dim MyStr As String
        Dim FilePath As String
        
        FilePath = "C:\aspi_update.zip"  ' whatever file !!
        
        ReDim Bytes(FileLen(FilePath))
        
        Open FilePath For Binary As #1
            Get #1, 1, Bytes
        Close
        
        MyStr = StrConv(Bytes, vbUnicode)
        Debug.Print MyStr
    
    End Sub

    ...and have a good weekend
    Paul Dwyer
    Network Engineer
    Aussie In Tokyo

    Using Powerbasic 6 & VB6 SP4 (Please also add your VB Version to your signature!)

  9. #9
    Fanatic Member
    Join Date
    Mar 2000
    Location
    That posh bit of England known as Buckinghamshire
    Posts
    658
    Paul,

    What about the InputB function. Would that do the trick?
    Iain, thats with an i by the way!

  10. #10
    Fanatic Member
    Join Date
    Feb 2000
    Location
    Japan
    Posts
    840
    Not sure,

    Probably would from what I read but I love byte arrays! I used them a couple of times once upon a time and fell in love with both the speed and versitility of them. I base a lot of my code around them now. You can do a lot with raw bytes.

    Byte arrays are good for viewing in locals and watch windows too.
    Paul Dwyer
    Network Engineer
    Aussie In Tokyo

    Using Powerbasic 6 & VB6 SP4 (Please also add your VB Version to your signature!)

  11. #11
    Guest

    Angry still not working

    It works fine in the debug window, but when i put it into a multiline textbox, it only shows the first few characters (unless it's a text file) How do i display this in a multiline text box?

  12. #12
    Fanatic Member
    Join Date
    Mar 2000
    Location
    That posh bit of England known as Buckinghamshire
    Posts
    658
    You don't.

    You've probably hit a charcter that the text box does not like, or one that tells the textbox that is the end of the string.
    Iain, thats with an i by the way!

  13. #13
    Guest

    huh?

    with all due respect, how could that be? Windows Notepad has no problem doing it. Is there maybe a function to send the text to the notepad as opposed to setting the text property? It cant be impossible!!!

  14. #14
    Fanatic Member
    Join Date
    Mar 2000
    Location
    That posh bit of England known as Buckinghamshire
    Posts
    658
    As i said you don't

    You use a RichTextBox instead. I was just testing to make sure it works.
    Iain, thats with an i by the way!

  15. #15
    Guest

    i guess....

    i guess you're right, but i just dont get how windows notepad can do it, since it is not a rich text box. whatever.

  16. #16
    Guest

    Why do a byte array?

    if using a rich text bos, then all you need to do, is object.LoadFile filename,1

  17. #17
    Fanatic Member
    Join Date
    Feb 2000
    Location
    Japan
    Posts
    840

    Exclamation

    Well,
    The origonal question didn't say anything about text boxes and RTF boxes so I dumped to a string. In fact the question doesn't really say what he's trying to achieve at all!

    The Byte array is still better while testing because if you decide against the RTFbox you can just swap it out. Besides the RTF Loadfile is no quicker than the byte array. I like the byte arrays because you can also build them in such a way that you can stick a bargraph on an incremental load, so if you're loading 50megs you can do see what's happening (percentage or whatever).

    Paul Dwyer
    Network Engineer
    Aussie In Tokyo

    Using Powerbasic 6 & VB6 SP4 (Please also add your VB Version to your signature!)

  18. #18
    Fanatic Member
    Join Date
    Feb 2000
    Location
    Japan
    Posts
    840

    Re: i guess....

    Originally posted by spetnik
    i guess you're right, but i just dont get how windows notepad can do it, since it is not a rich text box. whatever.
    Windows notepad is now 32bit, where as the textbox control is only 16bit so there is a limit to how much text it will let you hold. And, as lian17 said if the text box hits certain control chars (like ASCII EOF) it'll stop.

    Notepad is not just a vb text box, it's quite a bit more robust, as is the VB debug screen it seems.

    What are you trying to do?
    Paul Dwyer
    Network Engineer
    Aussie In Tokyo

    Using Powerbasic 6 & VB6 SP4 (Please also add your VB Version to your signature!)

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