|
-
Jun 16th, 2000, 12:13 AM
#1
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?
-
Jun 16th, 2000, 12:17 AM
#2
Fanatic Member
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!
-
Jun 16th, 2000, 12:21 AM
#3
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?
-
Jun 16th, 2000, 12:21 AM
#4
Fanatic Member
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!)
-
Jun 16th, 2000, 12:23 AM
#5
Fanatic Member
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!)
-
Jun 16th, 2000, 12:27 AM
#6
byte array?
How do i use byte-array (im unfamiliar w/ this term)
-
Jun 16th, 2000, 12:28 AM
#7
Fanatic Member
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!
-
Jun 16th, 2000, 12:37 AM
#8
Fanatic Member
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!)
-
Jun 16th, 2000, 12:39 AM
#9
Fanatic Member
Paul,
What about the InputB function. Would that do the trick?
Iain, thats with an i by the way!
-
Jun 16th, 2000, 12:45 AM
#10
Fanatic Member
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!)
-
Jun 16th, 2000, 12:48 AM
#11
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?
-
Jun 16th, 2000, 12:55 AM
#12
Fanatic Member
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!
-
Jun 16th, 2000, 12:57 AM
#13
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!!!
-
Jun 16th, 2000, 01:04 AM
#14
Fanatic Member
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!
-
Jun 16th, 2000, 01:05 AM
#15
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.
-
Jun 16th, 2000, 01:10 AM
#16
Why do a byte array?
if using a rich text bos, then all you need to do, is object.LoadFile filename,1
-
Jun 16th, 2000, 11:50 AM
#17
Fanatic Member
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!)
-
Jun 16th, 2000, 11:55 AM
#18
Fanatic Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|