From: Alexandros Peropulous on
Yes, I experienced this already.
I find it strange that that the get function is so inconsistent.
In my opinion it would have been a more straight-forward way if the
array should not have to be resized before the get call, since I also
don't need to resize the
a() As Byte
"subarray" or whatever one would call it...


Nobody:
> "Nobody"<nobody(a)nobody.com> wrote in message
> news:%23nFno6ZGLHA.5448(a)TK2MSFTNGP06.phx.gbl...
>> "Alexandros Peropulous"<peropero(a)gmail.com> wrote in message
>> news:eKgz1wZGLHA.3468(a)TK2MSFTNGP05.phx.gbl...
>>> My experience and what I read from Mike's answer was that I do need to
>>> "resize" the array to the needed size before calling "get", and I need to
>>> store the "length"/ "UBound" of the array somewhere, preferrably in the
>>> file itself.
>>
>> Correct. This is explained in MSDN under "Get statement".
>>
>
> Also, if you put the array in UDT and give the UDT var to Put/Get, then VB
> would save the array descriptor for you and do ReDim when "Get" is called.
> example code:
>
> Option Explicit
>
> Private Type TByte
> a() As Byte
> End Type
>
> Private Sub Form_Load()
> Dim f As Integer
> Dim udt As TByte
>
> ReDim udt.a(1 To 3)
>
> udt.a(1) = 65
> udt.a(2) = 66
> udt.a(3) = 67
>
> f = FreeFile
> Open "C:\vbtest.txt" For Binary As f
> Put f, , udt
> Close f
>
> Erase udt.a
>
> f = FreeFile
> Open "C:\vbtest.txt" For Binary As f
> Debug.Print "File size is "& LOF(f)
> Get f, , udt
> Close f
> Debug.Print LBound(udt.a), UBound(udt.a)
> Debug.Print udt.a(1)
> Debug.Print udt.a(2)
> Debug.Print udt.a(3)
>
> End Sub
>
>
> Output:
>
> File size is 13
> 1 3
> 65
> 66
> 67
>
>
>
>

From: Mike Williams on
"Larry Serflaten" <serflaten(a)gmail.com> wrote in message
news:i0isrn$sjm$1(a)news.eternal-september.org...

> You couldn't just say yes or no, could you? The
> short answer is no, the array does not need to be
> (re)dimensioned prior to reading in the data.

Actually the short answer is "YES"! What's up, Larry. Did you out of the
wrong side of the bed this morning? Have you got a sore head or something?
Looking at the OP's question in the context in which it was asked, and the
taking into account the fact that he was asking the question in response to
some example code of mine in which I sized (Dimensioned) the array once only
in the general declarations section, it is abundantly clear what the OP
meant by his question. The fact is that if you want to use the Get statement
to populate an array by loading data from a file (as we were doing) then you
MUST set the array to the appropriate size (Dim, Redim or whatever) before
using Get.

Hope your head gets better soon, Larry.

Mike




From: Mike Williams on
"Larry Serflaten" <serflaten(a)gmail.com> wrote in message
news:i0isrn$sjm$1(a)news.eternal-september.org...

> The guy asked about saving a single array, and you
> say; yeah, you can do a bunch if you do it a certain
> way.... What's up with that?

Actually the guy (as you so quaintly put it) asked a number of questions
about saving and loading what he called a huge Decision Tree involving lots
of parents and children, and his question regarding saving and loading an
array of Singles was in fact supplementary to his main question. The code I
posted in my own response addressed his supplementary question (saving and
loading an array of Singles) but I decided that in addition to posting that
code I would add a few notes about the general behaviour of the Put and Get
statements which may give the OP some clues as to how to go about answering
his main question for himself (since he is the only person at the moment who
knows the exact desired layout of his data).

Why have you got a problem with that Larry? What's up with you? I'm just
trying to be helpful.

Mike




From: Mike Williams on
"Larry Serflaten" <serflaten(a)gmail.com> wrote in message
news:i0jqpo$j5p$1(a)news.eternal-september.org...

> Step through this example below to see you
> do not need to know the size nor the number
> of dimensions, if that is a criteria....
> Dim dataOut As Variant
> ReDim dataOut(0 To 1, 0 To 1)
> Dim dataIn As Variant
> ' This variable [dataIn] is not sized

That's because the variable [dataIn] is not an array. It is a Variant which
in this specific case just happens to contain an array. The code works
because the Variant contains information about its contents and because that
information is saved along with the contents themselves, and the OP has
already been informed that he can do the same thing with array contained in
a UDT, and he has responded to it, and he then asked why the VB Get
statement does not treat as standard VB array in that manner, and the reason
was explained to him.

What you have shown him is simply a different way of saving an array
contained inside something else (contained inside a Variant in your example
rather than the UDT method he already knows about). Both the UDT and the
Variant know something about what they contain, and so that information is
saved alongside the contents themselves, but in the case of a UDT there is
no subsequent processing speed penalty for that whereas in the case of your
own suggested method of a Variant there very definitely is a speed penalty.

The OP was taking specifically about a very large array, as in his own
example of Dim myArr(10000, 10000) as Single, and your idea of saving and
loading them into a Variant is going to hugely slow down the subsequent
processing of that array and is going to make it run like a pig in treacle.
Your own example uses a Variant containing an array of Variants, which is
definitely going to be very slow when the time comes to process that array
data, but even if the OP changes that to a Variant containing an array of
Singles, his subsequent processing code on the array is still going to take
up to five times longer than it would do if he instead loaded the data into
a standard array of Singles or into an array of Singles within a UDT.

Mike




From: Mike Williams on
"Larry Serflaten" <serflaten(a)gmail.com> wrote in message
news:i0isrn$sjm$1(a)news.eternal-september.org...

> You couldn't just say yes or no, could you?

What's up, Larry? This is not the first time you have posted such a snidely
worded response to something I have posted. Is there something bothering
you? Did I perhaps pull you up on one of your own responses a long time ago,
something which I have forgotten about but which is perhaps still festering
in your brain and eating it away? If so then you need to let it go, Larry.
Chill.

Mike