Re: Add/remove zero index of array




"Tim Rude" <timrude@xxxxxxxxxxxxxxxxxx> wrote in message
news:OhZq6NkRIHA.4880@xxxxxxxxxxxxxxxxxxxxxxx
VB6:

I've got an array that starts with index 1 [i.e. Dim X(1 to n) as MyUDT
where MyUDT is all fixed length strings].

I need to either add a zero index to this array [X(1 to n) -> X(0 to n)]
or
*quickly* create a new zero-based array with all of the contents of X plus
the new zero index [X(1 to n) -> Y(0 to n)]. I know that ReDim Preserve
only
works on the top end of the array. I also need to be able to go the other
way [i.e. X(0 to n) -> X(1 to n) or X(0 to n) -> Y(1 to n), throwing away
X(0)].

Why do I need to do this?

I just discovered that I can read and write an entire UDT array to a disk
file in one fell swoop in Binary mode using Get/Put and it's orders of
magnitude faster than reading/writing one record at a time in Random
Access
mode. However, in the original program I only wrote records X(1 to n) of
the
array. X(0) never got written since it held some special info that was
internally generated on the fly.

For compatibility purposes, I cannot now include X(0) in the disk file.
The
file *must* maintain the same format.

So I need to use the 0-based array within the program but read/write a
1-based array to disk.


Rather than make guesses can you show the Binary Get/Put you are currently
using?
Is X(0) always the same length? Or does it have a reliable terminator? Do
the UDTs have a reliable 'begin' marker?

The reason I am asking is because it should be realitively easy to read the
file in one gulp, discard the first part, and then chunk up the rest. This
is done all the time, for example - dbf files.

-ralph


.



Relevant Pages

  • Re: Add/remove zero index of array
    ... If you do it correctly you can create and use your zero based array and when the time comes to save it you can save just elements onwards. ... Private Declare Sub CopyMemory Lib "kernel32" _ ... Private Type myUDT ... Dim arr1() As myUDT ...
    (microsoft.public.vb.general.discussion)
  • Re: Comparing User Defined Type variables
    ... > My question is regarding the comparison of two UDT variables. ... > I have an array of UDT, ... > I also have a function with a ByRef parameter of MyUDT. ...
    (microsoft.public.vb.general.discussion)
  • Re: Add/remove zero index of array
    ... If you do it correctly you can create and use your zero based array and when the time comes to save it you can save just elements onwards. ... Private Declare Sub CopyMemory Lib "kernel32" _ ... Private Type myUDT ... Dim arr1() As myUDT ...
    (microsoft.public.vb.general.discussion)
  • Comparing User Defined Type variables
    ... My question is regarding the comparison of two UDT variables. ... I have an array of UDT, ... I also have a function with a ByRef parameter of MyUDT. ... Can anyone help me in this regard? ...
    (microsoft.public.vb.general.discussion)
  • Add/remove zero index of array
    ... I've got an array that starts with index 1 [i.e. Dim Xas MyUDT ... in the original program I only wrote records Xof the ... I cannot now include Xin the disk file. ...
    (microsoft.public.vb.general.discussion)

Loading