Jim Mack
1/11/2012 7:38:00 PM
> I want to allocate a very-long string so that I can read data into it
> with a binary GET. Now I could...
>
> myString$ = Space(VeryBigNumber&)
> Open myFile$ for Binary as #23
> GET #23, , myString$
>
> First of all, I don't care about the contents of myString so there is
> no need to initialize it with spaces.
> Second: Space() and String() return a variant. I assume that VB6
> will then need to allocate the huge Variant as a string variable, and
> then copy the spaces into it before releasing the temporary Variant
> returned by Space().
>
> Since I can't specify a length parameter on the GET statement, is
> there a way to simply allocate a string variable?
Yes. Use Space$() instead of Space(). (-:
And Space$ is faster than String$ -- not much, but some.
Depending on how you'll use the data, Karl's suggestion of a byte array
might be optimal. But if you need it as a string, I don't think you
gain anything by avoiding what you show above. One way or another, VB
will read the file as binary data, then convert it to a string.
--
Jim