From: Alexandros Peropulous on
Hi Mike,

2 caveats as far as I have seen now:

1) The array needs to be (re)dimmed before I load it.
2) The other one, as I guess, is the *1* that you have both in your get
and put statements. For some reason intellisense does not pop up for me,
and what I have searched on the internet was not really tell me why you
use it. Can you help?
Does it tell the lbound of my array? I guess not...



Mike Williams:
> "Alexandros Peropulous"<peropero(a)gmail.com> wrote in message
> news:ug7ZaARGLHA.1868(a)TK2MSFTNGP05.phx.gbl...
>
>> I would also be glad to hear about how to blit let's say an array of this
>> kind into memory:
>> Dim myArr() as Single
>> Redim myArr(10000,10000)
>> I wonder if each value really has to be inserted
>> "manually" when loading or if there is a faster
>> method than this: For X = 1 to 10000
>> For Y = 1 to 10000 . . . etc
>
> Actually unless you've used Option Base 1 in your code then the above would
> not be correct anyway, because the array elements would be 0 to 10000 (as
> opposed to 1 to 10000). But, to answer your question, you can easily pull
> the entire array in from disk in one go, although personally I would not be
> happy with creating arrays of such a size and would probably choose a
> different method that allowed you to have only so much data as your app is
> currently dealing with in memory at any one time . . or at least to split
> the data up into a number of smaller blocks if you really do need to have it
> all in memory at once (much depends on what else your code is doing and how
> much memory it is using for other things, but generally it is always much
> easier for the system to find ten blocks of 40 MB than it is for it to find
> one block of 400 MB). Anyway, one way of loading the data from file in one
> go is to use the Get statement, as in the following simple example. You can
> use a straight forward array (as in the example) or you can use a similar
> method to load a UDT in one go, which gives you more flexibility:
>
> Option Explicit
> Private myArr(1000, 1000) As Single
>
> Private Sub Command1_Click()
> ' save the data
> Open "c:\temp\test1.dta" For Binary As 1
> Put #1, 1, myArray()
> Close 1
> End Sub
>
> Private Sub Command2_Click()
> ' load the data
> Open "c:\temp\test1.dta" For Binary As 1
> Get #1, 1, myArray()
> Close 1
> End Sub
>
> Mike
>
>
>
>
>
>> myArr(X, Y) = 'code to set value here...
>>
>

From: Larry Serflaten on

"Alexandros Peropulous" <peropero(a)gmail.com> wrote
> 2 questions:
>
> 1) I do have to know the array size and redim my array accordingly
> before loading it again, is that correct?

No, as shown:

Dim myArr() as Single
Redim myArr(10000,10000)

Vb will handle the file data going out, and returns the same size array
when you go to read it in. Open, Put, Get, and Close is all you need.

>
> 2) This does not work with objects. VB6 says that #Get and #Put do not
> support it... For example I can't put an array of user-defined types
> which point to a class.

Correct, while a UDT of scalar data types would work, objects, or
UDT's that contain objects does not. That doesn't mean its impossible,
it just means Microsoft did not supply code to do deep copies on user
objects. If you want to add that code, you are certainly welcome to....


> Would using an API function help or is that simply not possible, no
> matter what I do?

The trouble is, they couldn't know if your objects contained other objects,
or what else. They just didn't include code to handle that sort of thing.
One would suppose they left that up to the programmers, who know exactly
what needs storing.

They've devised a file format that allows them to save and read arrays
(of scalar types). You can devise a file format that allows you to save
objects. Of course how you do that is entirely your call. You alone know
what you need to store, so pick data structures that work well with what
you want to do with them.

What is your data? Would it fit nice in a string? etc...

Can you post a small example of the tree? (Nodes, if you have them...)

LFS


From: Mike Williams on
"Alexandros Peropulous" <peropero(a)gmail.com> wrote in message
news:e2UGCOSGLHA.6120(a)TK2MSFTNGP04.phx.gbl...
> Hi Mike,
> 2 caveats as far as I have seen now:
> 1) The array needs to be (re)dimmed before I load it.

The Get statement loads data from a file into a variable (or into an array
of variables) and it loads exactly the required number of bytes to fill up
that variable (or array). You can use Get to load a single variable or a
single array or a single UDT, or you can use it to load lots of variables
and arrays and UDTs from the same file. In order that it can do this you of
course need to tell it each time you use it how many bytes you want it to
load, which in this specific case you do by Dimensioning the array to the
required size before using the Get statement. Once the Get statement has
loaded the required data into the variable (or array) it then leaves the
"file byte pointer" pointing the file byte that immediately follows the data
it has just loaded.

> 2) The other one, as I guess, is the *1* that you have
> both in your get and put statements.

The "1" to which you are referring is the desired byte position from which
you want the Get statement to start reading its data (as far as the Get
statement is concerned the first byte of a file is byte number 1). In this
specific example we want to read the data starting from the very first byte
of the file, hence the second "1" in the line (the first "#1" of course is
the file number, although really I suppose you should use the freeFile
function instead of a hard coded "1" that I did purely out of laziness!).

Get #1, 1, myArray()

An alternative statement (in this specific example) would be:

Get #1, , myArray()

The above (in which we have ommitted the second parameter) would cause the
Get statement to start reading data from the current "file byte position"
(which I mentioned earlier), which in this specific example would be the
equivalent of Get #1, 1, myArray() because we are reading data from the file
immediatety after opening, at which time the file byte pointer will have
been initialiased to its starting value of 1. Because of the way they work
in this respect, the Put and Get statements are quite flexible.

> 1) The array needs to be (re)dimmed before I load it.

As a second note on that point, when you are loading data from a file you
must of course know something about the organisation of that data otherwise
the file would be meaningless (for example it would in most cases be
pointless loading a set of data representing an array of Singles into an
array of Longs). In the specific example I posted we knew the exact length
of the array (since the same project that saved the data was reading it
back) and so we could Dim the array to the exact required number of
elements. If however you are using Get and Put on a file to save arrays of
data (and possibly lots of other things) and if the code reading the file
does not know the length of the array that was saved (and especially if
there are other things saved to the file as well) then there are various
ways of solving that problem. On way would be to organise the file in such a
way that you Put the number of array elements to the file as a Long
immediately before Putting the actual array data, and then you can use Get
to read the Long into memory and Dim the array to the required size and then
use Get again to read the array data itself. There are all sorts of ways of
arranging these things. The important thing of course is that your code that
reads the file knows about the format of it, but then that applies to
everything. It is not a restriction.

Mike




From: Alexandros Peropulous on
Yes, okay, you really helped me!
I want to thank you very much!
I will definitively post a sample because I don't think I am already
done with my decision tree problem(s).
I will be on tour for 1 week, but after that I can work on it further.
When I post into this thread after 1 week, do you people see it
automatically?
I don't. I have to look specifically into this thread to see if you
wrote something, I am using Thunderbird and never really configured it
nicely.


Mike Williams:
> "Alexandros Peropulous"<peropero(a)gmail.com> wrote in message
> news:e2UGCOSGLHA.6120(a)TK2MSFTNGP04.phx.gbl...
>> Hi Mike,
>> 2 caveats as far as I have seen now:
>> 1) The array needs to be (re)dimmed before I load it.
>
> The Get statement loads data from a file into a variable (or into an array
> of variables) and it loads exactly the required number of bytes to fill up
> that variable (or array). You can use Get to load a single variable or a
> single array or a single UDT, or you can use it to load lots of variables
> and arrays and UDTs from the same file. In order that it can do this you of
> course need to tell it each time you use it how many bytes you want it to
> load, which in this specific case you do by Dimensioning the array to the
> required size before using the Get statement. Once the Get statement has
> loaded the required data into the variable (or array) it then leaves the
> "file byte pointer" pointing the file byte that immediately follows the data
> it has just loaded.
>
>> 2) The other one, as I guess, is the *1* that you have
>> both in your get and put statements.
>
> The "1" to which you are referring is the desired byte position from which
> you want the Get statement to start reading its data (as far as the Get
> statement is concerned the first byte of a file is byte number 1). In this
> specific example we want to read the data starting from the very first byte
> of the file, hence the second "1" in the line (the first "#1" of course is
> the file number, although really I suppose you should use the freeFile
> function instead of a hard coded "1" that I did purely out of laziness!).
>
> Get #1, 1, myArray()
>
> An alternative statement (in this specific example) would be:
>
> Get #1, , myArray()
>
> The above (in which we have ommitted the second parameter) would cause the
> Get statement to start reading data from the current "file byte position"
> (which I mentioned earlier), which in this specific example would be the
> equivalent of Get #1, 1, myArray() because we are reading data from the file
> immediatety after opening, at which time the file byte pointer will have
> been initialiased to its starting value of 1. Because of the way they work
> in this respect, the Put and Get statements are quite flexible.
>
>> 1) The array needs to be (re)dimmed before I load it.
>
> As a second note on that point, when you are loading data from a file you
> must of course know something about the organisation of that data otherwise
> the file would be meaningless (for example it would in most cases be
> pointless loading a set of data representing an array of Singles into an
> array of Longs). In the specific example I posted we knew the exact length
> of the array (since the same project that saved the data was reading it
> back) and so we could Dim the array to the exact required number of
> elements. If however you are using Get and Put on a file to save arrays of
> data (and possibly lots of other things) and if the code reading the file
> does not know the length of the array that was saved (and especially if
> there are other things saved to the file as well) then there are various
> ways of solving that problem. On way would be to organise the file in such a
> way that you Put the number of array elements to the file as a Long
> immediately before Putting the actual array data, and then you can use Get
> to read the Long into memory and Dim the array to the required size and then
> use Get again to read the array data itself. There are all sorts of ways of
> arranging these things. The important thing of course is that your code that
> reads the file knows about the format of it, but then that applies to
> everything. It is not a restriction.
>
> Mike
>
>
>
>

From: Nobody on
Whatever format you choose, I recommend that you save a version number
first, like "1", so in case you change the format later, you can tell which
version the format is in, and you don't have to come up with a new file
extension just because you changed the file format. Example:

Dim b As Byte

b = 1 ' Version number
Put f, , b
' Save the rest of the file

And upon reading:

Get f, , b
If b = 1 Then
' File has the correct version number, load the rest of the file
End If