Array saving question (lbound)

Hello!

I am saving an array to a file and then load it again.


     Open sPath For Binary As #iFile1

     If uLoad Then
         Get #iFile1, , uArray
     Else
         Put #iFile1, , uArray
     End If

My array looks like this:

Redim myArr(1 to 3) as long
myArr(1) = 100
myArr(2) = 500
myArr(3) = 10000

When I load it again, I say:

Redim MyNewArr(1 to 3) and call the above sub.

For some reason, MyNewArr now looks like this:

MyNewArr(0) = 100
MyNewArr(1) = 500
MyNewArr(2) = 3

When I try to access MyNewArr(3) an out of bounds error is thrown.

Can somebody please tell me how to save my array correctly so that it 
will start at 1 again, just like I declared it when redimming it?

Thank you!


0
Boris
9/11/2010 5:30:38 PM
vb.general.discussion 1016 articles. 0 followers. Follow

22 Replies
2006 Views

Similar Articles

[PageSpeed] 57

on 9/11/2010, Boris P. supposed :
> Hello!
>
> I am saving an array to a file and then load it again.
>
>
>      Open sPath For Binary As #iFile1
>
>      If uLoad Then
>          Get #iFile1, , uArray
>      Else
>          Put #iFile1, , uArray
>      End If
>
> My array looks like this:
>
> Redim myArr(1 to 3) as long
> myArr(1) = 100
> myArr(2) = 500
> myArr(3) = 10000
>
> When I load it again, I say:
>
> Redim MyNewArr(1 to 3) and call the above sub.
>
> For some reason, MyNewArr now looks like this:
>
> MyNewArr(0) = 100
> MyNewArr(1) = 500
> MyNewArr(2) = 3
>
> When I try to access MyNewArr(3) an out of bounds error is thrown.
>
> Can somebody please tell me how to save my array correctly so that it will 
> start at 1 again, just like I declared it when redimming it?
>
> Thank you!

By default arrays are zero based. So a 3 element array will always 
begin with 0 and end with 2. You have to declare Option Base to 1 if 
you want to go that way. However, I strongly recommend you modify your 
thinking to use the default zero base. (It'll make life much 
easier!<g>)

-- 
Garry

Free usenet access at http://www.eternal-september.org
ClassicVB Users Regroup! comp.lang.basic.visual.misc


0
GS
9/11/2010 9:06:38 PM
GS wrote:
> on 9/11/2010, Boris P. supposed :
>> Hello!
>>
>> I am saving an array to a file and then load it again.
>>
>>
>>      Open sPath For Binary As #iFile1
>>
>>      If uLoad Then
>>          Get #iFile1, , uArray
>>      Else
>>          Put #iFile1, , uArray
>>      End If
>>
>> My array looks like this:
>>
>> Redim myArr(1 to 3) as long
>> myArr(1) = 100
>> myArr(2) = 500
>> myArr(3) = 10000
>>
>> When I load it again, I say:
>>
>> Redim MyNewArr(1 to 3) and call the above sub.
>>
>> For some reason, MyNewArr now looks like this:
>>
>> MyNewArr(0) = 100
>> MyNewArr(1) = 500
>> MyNewArr(2) = 3
>>
>> When I try to access MyNewArr(3) an out of bounds error is thrown.
>>
>> Can somebody please tell me how to save my array correctly so that it 
>> will start at 1 again, just like I declared it when redimming it?
>>
>> Thank you!
> 
> By default arrays are zero based. So a 3 element array will always begin 
> with 0 and end with 2. You have to declare Option Base to 1 if you want 
> to go that way. However, I strongly recommend you modify your thinking 
> to use the default zero base. (It'll make life much easier!<g>)

I'd say "it depends" on whether to use 0- or 1-based indexing, dependent 
upon the problem domain.

Note that ReDim() should _not_ be used except for redimensioning, not 
for initial declarations  -- see the Caution discussion in the language 
reference manual for ReDim.

In short, the above code snippet should start w/ a

Dim myArr() As Long
ReDim myArr(1 to 3)

There's a problem w/ the code and the symptoms described as well--I 
strongly suspect the code isn't as typed in (and can tell it isn't 
copied and pasted as the capitalization for keywords isn't consistent w/ 
the VB stylistic pattern).

The statement

Redim MyNewArr(1 to 3)

isn't complete, either, as the "As Long" clause is missing and the 
existence of the (1 To 3) if it were in the actual code would preclude 
the appearance of MyNewArr(0) as the upper and lower bound subscripts 
are explicitly given.

I suspect that what you _actually_ have is

ReDim MyNewArr(3)

instead which would behave as GS notes assuming there is no

Option Base 1

statement in effect.

Lesson to be learned -- when posting code that is to demonstrate a 
symptom, post the actual code and the symptom, not a paraphrasing of it.

--
0
dpb
9/11/2010 9:29:57 PM

"GS" <gesansom@netscape.net> wrote in message 
news:i6gr11$u8s$1@news.eternal-september.org...
> on 9/11/2010, Boris P. supposed :

>
> By default arrays are zero based. So a 3 element array will always begin 
> with 0 and end with 2. You have to declare Option Base to 1 if you want to 
> go that way. However, I strongly recommend you modify your thinking to use 
> the default zero base. (It'll make life much easier!<g>)


No, that's incorrect. If you do NOT specify a lower bound, only then the 
default is 0.  Otherwise, the lower bound is whatever you specify in your 
Dim/ReDim. Option Base 1 just means that if you DON'T specify the lower 
bound, it will default to 1 instead of 0.

I also can't agree with your recommendation. In some cases, sure, the array 
should be 0-based.  For example, if syncing it to something that is 0-based 
(a listbox, for example). Otherwise, I personally view it as "programmer's 
preference".

-- 
Mike
 

0
MikeD
9/11/2010 10:31:29 PM
MikeD submitted this idea :
>
> "GS" <gesansom@netscape.net> wrote in message 
> news:i6gr11$u8s$1@news.eternal-september.org...
>> on 9/11/2010, Boris P. supposed :
>
>>
>> By default arrays are zero based. So a 3 element array will always begin 
>> with 0 and end with 2. You have to declare Option Base to 1 if you want to 
>> go that way. However, I strongly recommend you modify your thinking to use 
>> the default zero base. (It'll make life much easier!<g>)
>
>
> No, that's incorrect. If you do NOT specify a lower bound, only then the 
> default is 0.

That was implied in the context of the OP's problem! Dumping a file 
into an array with 'Get' will result in a zero-based array UNLESS 
Option Base 1 is declared. That's all I was responding to.

>  Otherwise, the lower bound is whatever you specify in your 
> Dim/ReDim. Option Base 1 just means that if you DON'T specify the lower 
> bound, it will default to 1 instead of 0.

No disagreement here.

>
> I also can't agree with your recommendation. In some cases, sure, the array 
> should be 0-based.  For example, if syncing it to something that is 0-based 
> (a listbox, for example). Otherwise, I personally view it as "programmer's 
> preference".

And as a programmer's preference, it was my recommendation to not use 
it 'generally speaking'! Again, no disagreement that it does have a 
place if one chooses to accept the resposibility of managing it in 
those cases. Personally, I've never found any practical reasons to 
suffice using Option Base 1.<g>

Not to raise contention.., but just to clarify!

-- 
Garry

Free usenet access at http://www.eternal-september.org
ClassicVB Users Regroup! comp.lang.basic.visual.misc


0
GS
9/12/2010 1:34:05 AM
GS wrote:
....

> That was implied in the context of the OP's problem! Dumping a file into 
> an array with 'Get' will result in a zero-based array UNLESS Option Base 
> 1 is declared. That's all I was responding to.
....

The Get doesn't really have anything to do with...unless the variable 
has been declared as a variable, it's a scalar and only a single value 
will be returned on the Get (ignoring the details of descriptors for 
dynamic strings/arrays or UDTs).

The dimensions of the array are based on the Dim or ReDim used and the 
Option Base in effect at the time.

The problem w/ OP's posting is that his posted code doesn't reflect the 
actual code--it's missing the definition of the calling sequence in the 
subroutine snippet and the location with respect to that of where he 
looked at the data and how.  The array name he complains of isn't the 
same as the array name in the routine so it isn't that that caused the 
problem.

There's also the problem noted above of whether he's reading/writing the 
same type of array -- if it was dynamic on Put, it needs to be dynamic 
matching on Get or he's going to get the descriptor information 
confounded w/ the data.  Conversely, if Put a fixed-sized array, only 
the data (no descriptors) will be written and trying to read it into a 
dynamic array will confound the data w/ descriptors the other direction.

The upshot still is, OP needs to post the actual code to be able to see 
precisely what caused the specific symptom(s) but he's got problems of 
inconsistency and poor practice at a minimum...

--
0
dpb
9/12/2010 1:52:17 AM
dpb wrote:
....

> The Get doesn't really have anything to do with...unless the variable 
> has been declared as a variable, ...

That of course was intended to read "declared as an array, ..."

--
0
dpb
9/12/2010 1:54:20 AM
Well stated.., and I agree.

Sorry I wasn't giving focus past the use of 'Get' and 'Put' in the 
concept of the posted code so much as how the array[s] were dimmed 
going to and coming back from the file.

As far as I'm concerned, my experience bears out that both you and Mike 
D have made valid points that I fully agree with. Personally, I've 
never mixed static/dynamic arrays in this usage knowing that Put/Get 
require everything be the same both ways or there's going to be 
problems.

Just seemed the LBound/UBound issue was related to the Option Base used 
(or not used)<g>

-- 
Garry

Free usenet access at http://www.eternal-september.org
ClassicVB Users Regroup! comp.lang.basic.visual.misc


0
GS
9/12/2010 3:27:21 AM
Yes, you're right, thanks! I did make the mistake of typing (0 to 3) 
instead of (1 to 3).
I am glad I mistyped it and you noticed that it was not copied!

The reason why I use 1-based arrays is that else I can never say if an 
array is actually empty!

Let's take a real-life sample:

I have a public var name colMyCustomers() which is made of udts

Public Type udtCustomer
	FirstName as string
	LastName as string
	(etc...)
End Type

public sub GetCustomers()

	Redim colCustomers(0)

	dim r as dhrichclient.crecordset
	set r = cn.openrecordset("SELECT * FROM customers")

	redim colCustomers(1 to r.recordcount)
	dim l&
	for l = 1 to r.recordcount
		colCustomers(l).firstname = r!customer_firstname
		colCustomers(l).lastname = r!customer_lastname
		(etc...)
  	r.movenext
	next l

end sub

The later in the code when I access the array, I can simply say

For l = 1 to ubound(colcustomer)
	etc...
Next l

When the array is still empty, it will simply skip it.
What would I do if the array was 0 based?

I would have to store in another variable if the array is really empty 
or has 1 customer (=colCustomer(0)).

And if I had not redimmed the array to 0 (Redim colCustomers(0)), any 
attemps to do something like this

For l = 1 to ubound(colcustomer)
	etc...
Next l

would throw an error because the array is not dimmed.

Anything wrong with my method?



dpb wrote:
> GS wrote:
>> on 9/11/2010, Boris P. supposed :
>>> Hello!
>>>
>>> I am saving an array to a file and then load it again.
>>>
>>>
>>> Open sPath For Binary As #iFile1
>>>
>>> If uLoad Then
>>> Get #iFile1, , uArray
>>> Else
>>> Put #iFile1, , uArray
>>> End If
>>>
>>> My array looks like this:
>>>
>>> Redim myArr(1 to 3) as long
>>> myArr(1) = 100
>>> myArr(2) = 500
>>> myArr(3) = 10000
>>>
>>> When I load it again, I say:
>>>
>>> Redim MyNewArr(1 to 3) and call the above sub.
>>>
>>> For some reason, MyNewArr now looks like this:
>>>
>>> MyNewArr(0) = 100
>>> MyNewArr(1) = 500
>>> MyNewArr(2) = 3
>>>
>>> When I try to access MyNewArr(3) an out of bounds error is thrown.
>>>
>>> Can somebody please tell me how to save my array correctly so that it
>>> will start at 1 again, just like I declared it when redimming it?
>>>
>>> Thank you!
>>
>> By default arrays are zero based. So a 3 element array will always
>> begin with 0 and end with 2. You have to declare Option Base to 1 if
>> you want to go that way. However, I strongly recommend you modify your
>> thinking to use the default zero base. (It'll make life much easier!<g>)
>
> I'd say "it depends" on whether to use 0- or 1-based indexing, dependent
> upon the problem domain.
>
> Note that ReDim() should _not_ be used except for redimensioning, not
> for initial declarations -- see the Caution discussion in the language
> reference manual for ReDim.
>
> In short, the above code snippet should start w/ a
>
> Dim myArr() As Long
> ReDim myArr(1 to 3)
>
> There's a problem w/ the code and the symptoms described as well--I
> strongly suspect the code isn't as typed in (and can tell it isn't
> copied and pasted as the capitalization for keywords isn't consistent w/
> the VB stylistic pattern).
>
> The statement
>
> Redim MyNewArr(1 to 3)
>
> isn't complete, either, as the "As Long" clause is missing and the
> existence of the (1 To 3) if it were in the actual code would preclude
> the appearance of MyNewArr(0) as the upper and lower bound subscripts
> are explicitly given.
>
> I suspect that what you _actually_ have is
>
> ReDim MyNewArr(3)
>
> instead which would behave as GS notes assuming there is no
>
> Option Base 1
>
> statement in effect.
>
> Lesson to be learned -- when posting code that is to demonstrate a
> symptom, post the actual code and the symptom, not a paraphrasing of it.
>
> --

0
Boris
9/12/2010 7:13:05 AM
dpb wrote:
> GS wrote:
> ...
>
>> That was implied in the context of the OP's problem! Dumping a file
>> into an array with 'Get' will result in a zero-based array UNLESS
>> Option Base 1 is declared. That's all I was responding to.
> ...
>
> The Get doesn't really have anything to do with...unless the variable
> has been declared as a variable, it's a scalar and only a single value
> will be returned on the Get (ignoring the details of descriptors for
> dynamic strings/arrays or UDTs).
>
> The dimensions of the array are based on the Dim or ReDim used and the
> Option Base in effect at the time.
>
> The problem w/ OP's posting is that his posted code doesn't reflect the
> actual code--it's missing the definition of the calling sequence in the
> subroutine snippet and the location with respect to that of where he
> looked at the data and how. The array name he complains of isn't the
> same as the array name in the routine so it isn't that that caused the
> problem.
>
> There's also the problem noted above of whether he's reading/writing the
> same type of array -- if it was dynamic on Put, it needs to be dynamic
> matching on Get or he's going to get the descriptor information
> confounded w/ the data. Conversely, if Put a fixed-sized array, only the
> data (no descriptors) will be written and trying to read it into a
> dynamic array will confound the data w/ descriptors the other direction.
>
> The upshot still is, OP needs to post the actual code to be able to see
> precisely what caused the specific symptom(s) but he's got problems of
> inconsistency and poor practice at a minimum...
>
> --


My code is huge and I cannot post it without leaving out things, and to 
make it clear, I rewrote it on the fly.

But my actual problem was that when I declared/ dimmed/ redimmed it, I chose

Redim (1 to ...)
and saved it this way.

But before loading it again from the file on the disk, I said "Redim (0 
to ...)"

This caused the array to start at 0 instead of 1.

Learnt something...

Normally, I only use DBs to write my data, not binary files, that's why 
your statement of "lack of consistency and practice" is right in this case.
0
Boris
9/12/2010 7:48:44 AM
But the actual problem remains:

How would one know if an array is empty when it's zero based???

I don't understand people who use 0-based arrays because they have to 
use another variable to check if the array is really empty.

With 0-based I mean arrays that have data in the index 0 position.
I do use 0-based arrays as well, but it doesn't contain data at that 
position.

I only use it to check if the array is "empty" or not.
0
Boris
9/12/2010 7:52:18 AM
Perhaps everybody will understand my way of coding with this sample.
I think it's really beautiful code:

Private Sub Form_Load()

     Dim s() As String
     ReDim s(0)

     Debug.Print "We have " & UBound(s) & " items"
     Dim l&
     For l = 1 To UBound(s)
         'if array is redimmed to 0, it will simply skip here
         Debug.Print "Item value " & l & " is " & s(l)
     Next l

     ReDim s(1)
     Debug.Print "We have " & UBound(s) & " items"
     For l = 1 To UBound(s)
         Debug.Print "Item value " & l & " is " & s(l)
     Next l

End Sub
0
Boris
9/12/2010 8:08:17 AM
"dpb" <none@non.net> wrote in message 
news:i6hbvp$ovo$1@news.eternal-september.org...

> There's also the problem noted above of whether
> he's reading/writing the same type of array -- if it
> was dynamic on Put, it needs to be dynamic matching on Get or he's going 
> to get the descriptor
> information confounded w/ the data.  Conversely,
> if Put a fixed-sized array, only the data (no descriptors)
> will be written and trying to read it into a dynamic
> array will confound the data w/ descriptors . . .

Actually that is not true (unless the array happens to be a member of a UDT, 
which in the OP's case it does not appear to be). When writing an ordinary 
array (one that is not a member of a UDT) then Put writes /exactly/ the same 
data to the file regardless of whether that array is dynamic or fixed size.

For example, if the array is an array of Longs containing three elements 
then exactly 12 bytes will be written to the file, regardless of whether the 
array is dynamic or fixed size, and for a three element array of Doubles the 
data written would be 24 bytes, again regardless of whether it was a dynamic 
or fixed size array. Similarly, the data written to file for each element of 
a three element array of Variants would be a two byte value representing the 
Data Type of the element followed by however many bytes the contents of that 
specific element requires (which of course depends on its data type). But 
even then, exactly the same data would be written to the file regardless of 
whether the array was dynamic or fixed size.

Mike



0
Mike
9/12/2010 10:03:34 AM
"Boris P." <bpnotvalid@nospamhotmail.com> wrote in message 
news:%23GNuk8kULHA.4872@TK2MSFTNGP02.phx.gbl...

> My code is huge and I cannot post it without leaving
> out things, and to make it clear, I rewrote it on the fly.
> But my actual problem was that when I declared/
> dimmed/ redimmed it, I chose Redim (1 to ...) and
> saved it this way. But before loading it again from the
> file on the disk, I said "Redim (0 to ...)"

Well that is not what you said in your original post. In fact you said 
something quite different, and it is NOT because you failed to post your 
full project code (which is perfectly understandable) but it is in fact 
because you ADDED some code that was not actually there! If you post the 
wrong code, and especially if (as you did) you tell us you used code that 
you did not actually use, then you should expect the wrong answer! In any 
case, what you have just said still does NOT explain why after saving the 
following data . . .

           myArr(1) = 100
           myArr(2) = 500
           myArr(3) = 10000

.. . . you got back the following data . . .

           MyNewArr(0) containing the value 100
           MyNewArr(1) containing the value 500
           MyNewArr(2) containing the value 3

Where the hell did the "3" come from! What you did was to post code that you 
were not actually using, and also post results that you were not actually 
getting!

> My code is huge and I cannot post it without leaving
> out things, and to make it clear, I rewrote it on the fly.

Yes. We understand that you cannot post everything, but you really should do 
your best to post all of the code and declarations that are appropriate to 
the specific small part of the project you are having problems with, and you 
very definitely should write the code you are about to post into an actual 
VB code window, and you should check the results that the code you have just 
typed actually returns in a running VB project, so that you do not end up 
posting code that you did not actually use, or missing out important parts, 
and also so that you do not end up posting results that did not actually 
happen!

One other example example in this particular case is that we had no idea 
whether you had properly initially declared your dynamic arrays rather than 
using Redim on the fly to do it, and in view of the line Redim myArr(1 to 3) 
as Long which was contained in your posted code we quite reasonably assumed 
that you had not properly initially declared them (since it is not usual to 
specify the data type again in a Redim statement). In your case you 
specified the data type in the Redim statement for one array but you did not 
specify the data type in your Redim statement for the other array, an 
inconsistency which made it appear that you might possibly be using Redim on 
the fly rather than initially properly declaring your dynamic arrays, and an 
inconsistency which led us to make other quite reasonable assumptions about 
your code which were probably not correct, for example the assumption that 
MyNewArr might actually be an array of Variants. Now I know that if it was 
an array of Variants then you would have had other problems in your code 
that you did not appear to be having if your posted results of the Get were 
correct, but the fact that one of the values returned in your posted results 
was the number 3, which was clearly not what you were actually getting, 
caused us to treat those posted results with suspicion anyway.

If you want to get the best answers then you should post your question in 
the best way you can, otherwise you will end up having everyone else 
guessing what you have actually done and unnecessarily running around in 
circles on your behalf.

Essentially, if you want people to do some work answering your question (as 
the people here do) then you should be prepared to do at least a similar 
amount of work asking it.

Mike



0
Mike
9/12/2010 11:12:01 AM
Boris P. wrote:
> But the actual problem remains:
>
> How would one know if an array is empty when it's zero based???
>
> I don't understand people who use 0-based arrays because they have
> to use another variable to check if the array is really empty.

Or they use error trapping (errors are information, not failures). Or
they probe the SAFEARRAY structure -- as does our Stamina library,
which has a function (DxArrayDims) that returns the number of
dimensions in an array. It returns 0 if the array is currently
undimmed.

There's nothing wrong what you're doing, but some (like me) find it a
bit odd.

-- 
     Jim Mack
     MicroDexterity Inc     www.microdexterity.com

0
Jim
9/12/2010 11:58:35 AM
"Boris P." <bpnotvalid@nospamhotmail.com> wrote in message 
news:eqmkeHlULHA.4576@TK2MSFTNGP04.phx.gbl...

> Perhaps everybody will understand my way of coding
> with this sample. I think it's really beautiful code:
>     Dim s() As String
>     ReDim s(0) Debug.Print "We have " & UBound(s) & " items"
>     Dim l&
>     For l = 1 To UBound(s)
>         'if array is redimmed to 0, it will simply skip here
>         Debug.Print "Item value " & l & " is " & s(l)
>     Next l

Well, each to his own I suppose. The contents of a file only really make 
sense to code that knows the format of the data, and since it is your own 
data and your own file then that's okay. It's just a bit unusual. By the 
way, your code above will fail with a Subscript Out Of Range error if you 
happen to paste it into a module that is using Option Base 1.

Mike


0
Mike
9/12/2010 1:27:28 PM
 From a certain project size on and with lots of tweaks like subclassing 
and altering tables, VB6 crashes at simple errors, that's why I try to 
avoid errors like hell.

Jim Mack:
> Boris P. wrote:
>> But the actual problem remains:
>>
>> How would one know if an array is empty when it's zero based???
>>
>> I don't understand people who use 0-based arrays because they have
>> to use another variable to check if the array is really empty.
>
> Or they use error trapping (errors are information, not failures). Or
> they probe the SAFEARRAY structure -- as does our Stamina library,
> which has a function (DxArrayDims) that returns the number of
> dimensions in an array. It returns 0 if the array is currently
> undimmed.
>
> There's nothing wrong what you're doing, but some (like me) find it a
> bit odd.
>

0
Boris
9/12/2010 1:41:15 PM
  Mike Williams:
> "Boris P." <bpnotvalid@nospamhotmail.com> wrote in message
> news:%23GNuk8kULHA.4872@TK2MSFTNGP02.phx.gbl...
>
>> My code is huge and I cannot post it without leaving
>> out things, and to make it clear, I rewrote it on the fly.
>> But my actual problem was that when I declared/
>> dimmed/ redimmed it, I chose Redim (1 to ...) and
>> saved it this way. But before loading it again from the
>> file on the disk, I said "Redim (0 to ...)"
>
> Well that is not what you said in your original post. In fact you said
> something quite different, and it is NOT because you failed to post your
> full project code (which is perfectly understandable) but it is in fact
> because you ADDED some code that was not actually there! If you post the
> wrong code, and especially if (as you did) you tell us you used code
> that you did not actually use, then you should expect the wrong answer!
> In any case, what you have just said still does NOT explain why after
> saving the following data . . .
>
> myArr(1) = 100
> myArr(2) = 500
> myArr(3) = 10000
>
> . . . you got back the following data . . .
>
> MyNewArr(0) containing the value 100
> MyNewArr(1) containing the value 500
> MyNewArr(2) containing the value 3
>
> Where the hell did the "3" come from! What you did was to post code that
> you were not actually using, and also post results that you were not
> actually getting!
>
>> My code is huge and I cannot post it without leaving
>> out things, and to make it clear, I rewrote it on the fly.
>
> Yes. We understand that you cannot post everything, but you really
> should do your best to post all of the code and declarations that are
> appropriate to the specific small part of the project you are having
> problems with, and you very definitely should write the code you are
> about to post into an actual VB code window, and you should check the
> results that the code you have just typed actually returns in a running
> VB project, so that you do not end up posting code that you did not
> actually use, or missing out important parts, and also so that you do
> not end up posting results that did not actually happen!
>
> One other example example in this particular case is that we had no idea
> whether you had properly initially declared your dynamic arrays rather
> than using Redim on the fly to do it, and in view of the line Redim
> myArr(1 to 3) as Long which was contained in your posted code we quite
> reasonably assumed that you had not properly initially declared them
> (since it is not usual to specify the data type again in a Redim
> statement). In your case you specified the data type in the Redim
> statement for one array but you did not specify the data type in your
> Redim statement for the other array, an inconsistency which made it
> appear that you might possibly be using Redim on the fly rather than
> initially properly declaring your dynamic arrays, and an inconsistency
> which led us to make other quite reasonable assumptions about your code
> which were probably not correct, for example the assumption that
> MyNewArr might actually be an array of Variants. Now I know that if it
> was an array of Variants then you would have had other problems in your
> code that you did not appear to be having if your posted results of the
> Get were correct, but the fact that one of the values returned in your
> posted results was the number 3, which was clearly not what you were
> actually getting, caused us to treat those posted results with suspicion
> anyway.
>
> If you want to get the best answers then you should post your question
> in the best way you can, otherwise you will end up having everyone else
> guessing what you have actually done and unnecessarily running around in
> circles on your behalf.
>
> Essentially, if you want people to do some work answering your question
> (as the people here do) then you should be prepared to do at least a
> similar amount of work asking it.
>
> Mike
>
>
>

Sorry, I become only assured of what I'm doing after all the responses here.
Over the years I did it without thinking about it, so I was sure I 
posted all info that was needed. Of course with your questions and tipps 
I found out that it's not as I thought it was.

0
Boris
9/12/2010 1:43:29 PM
Mike Williams wrote:
....

> Actually that is not true (unless the array happens to be a member of a 
> UDT, which in the OP's case it does not appear to be). When writing an 
> ordinary array (one that is not a member of a UDT) then Put writes 
> /exactly/ the same data to the file regardless of whether that array is 
> dynamic or fixed size.
....

For Binary mode that's true, indeed.  I should have noted the Open was 
included in OP's posting, sorry.

--

0
dpb
9/12/2010 1:49:26 PM
"Boris P." <bpnotvalid@nospamhotmail.com> wrote in message 
news:eqmkeHlULHA.4576@TK2MSFTNGP04.phx.gbl...
> Perhaps everybody will understand my way of coding with this sample.
> I think it's really beautiful code:
>
> Private Sub Form_Load()
>
>     Dim s() As String
>     ReDim s(0)
>
>     Debug.Print "We have " & UBound(s) & " items"
>     Dim l&
>     For l = 1 To UBound(s)
>         'if array is redimmed to 0, it will simply skip here
>         Debug.Print "Item value " & l & " is " & s(l)
>     Next l
>
>     ReDim s(1)
>     Debug.Print "We have " & UBound(s) & " items"
>     For l = 1 To UBound(s)
>         Debug.Print "Item value " & l & " is " & s(l)
>     Next l
>
> End Sub

See IsDimmed() here as an alternative:

http://groups.google.com/group/microsoft.public.vb.enterprise/msg/6925f09068af63a5

It uses error trapping. Here is ArrayDimmed() that doesn't use error 
trapping:

http://groups.google.com/group/microsoft.public.vb.general.discussion/msg/8d0862e83b1a27cc


0
Nobody
9/12/2010 2:05:10 PM
"Boris P." <bpnotvalid@nospamhotmail.com> wrote

> From a certain project size on and with lots of tweaks like subclassing
> and altering tables, VB6 crashes at simple errors, that's why I try to
> avoid errors like hell.

Altering V-Tables?

That's a bit funny.  You hack into Windows messages, and maybe
muck about with VB's jump tables....

.... but try to handle data in a file and you find VB isn't doing what
you want!

Priceless!
LFS


0
Larry
9/12/2010 6:50:40 PM
dpb wrote:
> Mike Williams wrote:
> ...
> 
>> Actually that is not true (unless the array happens to be a member of 
>> a UDT, which in the OP's case it does not appear to be). When writing 
>> an ordinary array (one that is not a member of a UDT) then Put writes 
>> /exactly/ the same data to the file regardless of whether that array 
>> is dynamic or fixed size.
> ...
> 
> For Binary mode that's true, indeed.  I should have noted the Open was 
> included in OP's posting, sorry.

Actually, was really responding more to the GS posting that seemed to 
indicate that somehow the Get operation was dynamically assigning memory 
and somehow affecting what the array indices were going to be and then 
got off into thinking how anything could affect the OPs symptoms and 
that led to the thinking of Random, not Binary access and from there the 
rest followed... :)

--
0
dpb
9/12/2010 7:05:24 PM
"Boris P." <bpnotvalid@nospamhotmail.com> skrev i meddelandet 
news:eqmkeHlULHA.4576@TK2MSFTNGP04.phx.gbl...
> Perhaps everybody will understand my way of coding with this sample.
> I think it's really beautiful code:
>
> Private Sub Form_Load()
>
>     Dim s() As String
>     ReDim s(0)
>
>     Debug.Print "We have " & UBound(s) & " items"
>     Dim l&
>     For l = 1 To UBound(s)
>         'if array is redimmed to 0, it will simply skip here
>         Debug.Print "Item value " & l & " is " & s(l)
>     Next l
>
>     ReDim s(1)
>     Debug.Print "We have " & UBound(s) & " items"
>     For l = 1 To UBound(s)
>         Debug.Print "Item value " & l & " is " & s(l)
>     Next l
>
> End Sub

What is wrong about Erase, except you have to deal with an error?

/Henning


0
Henning
9/12/2010 7:15:50 PM
Reply:

Similar Artilces:

Exchange 2003 Question #3
Dear all, I have upgraded from Exchange 5.5 and notice that I miss the feature where I can clean/delete mail based on certain criteria from users mailbox via the System Manager. Is this feature still available in Exchange 2003, If so, where is it? Thanks. Regards, Kueh. You can use ExMerge to remove emails based on certain criteria (ie. attachment name, subject, etc). http://www.msexchange.org/tutorials/MF013.html "KA Kueh" wrote: > Dear all, > > I have upgraded from Exchange 5.5 and notice that I miss the feature where I > can clean/delete mail based on ...

Question On Fields
What is the (Microsoft desciption)difference between the SIC field and the Industry Code field? To me they seem like a duplication. Thanks! Shauna Hi, According to the Deployment Manager descriptions of attributes: SIC - Standard Industrial Classification code for the Account industrycode - the type of industry with which the account is associated... Hope this helps! "Shauna Koppang" <anonymous@discussions.microsoft.com> wrote in message news:034101c48af4$62524a70$a401280a@phx.gbl... > What is the (Microsoft desciption)difference between the > SIC field and the...

newbie question
Excel help says it should be a tab under tools, but I can't see it in my version. I would appreciate any help. Thanks. You must first load the Solver Add-in through Tools>Add-ins. Gord Dibben MS Excel MVP On Sat, 03 Nov 2007 07:46:34 -0700, analyst41@hotmail.com wrote: >Excel help says it should be a tab under tools, but I can't see it in >my version. > >I would appreciate any help. > >Thanks. On Nov 3, 10:56 am, Gord Dibben <gorddibbATshawDOTca> wrote: > You must first load the Solver Add-in through Tools>Add-ins. > > Gord Dibben MS E...

REQ: Can Someone Help Me With This Outlook XP Question?
Hello All: I use Word to edit my e-mail msgs in Outlook XP. I had to reinstall Office the other day and now whenever I want to start a new e-mail or reply to an e-mail I get a warning that comes up: "A program is trying to access e-mail addresses you have stored in Outlook. Do you want to allow this? If this is unexpected it may be a virus and you should choose 'No'" There is a box that asks for the amount of time to allow the access: 1 to 10 minutes. Do I have to have specific settings for my Outlook address book? I use the Contact area in Outlook for addresses. I have ...

Baseball Stats question: How can I get the RBI's?
I have a data table that looks like this: Code ------------------- STR-S SNK-S STR-K STR-F SNK-S STR-3 STR-2 STR-F SNK-S SNK-4 SNK-S STR-3 SNK-F STR-4 STR-O ------------------- "STR", etc at the beginning are pitch types, SNK is Sinker for example The end character is the result of the pitch, a 4 would be a home run, 3 a triple, and so forth. O is out, F is foul, S is strike --- you ge it. How can I figure the amount of RBI's? I know that it's 5, but I can' think of any automated way to calculate this, anyone got any ideas? THANK YOU!! :confused -- AVER...

Formula Question #18
I have built a workbook in which I have inserted a formula to tell me whether the contents of a supply bin needs replenishment or not. The formula I used is: =IF(E3>F3,"REPLENISH!","No Action"). Each morning, I run a report to see what parts have been used, which becomes a new sheet in the workbook. Now, I want to add a formula that, whenever it sees "REPLENISH!," it will back through the workbook to count whether that same part needed replenishment on consecutive previous days. If it has, then the latest worksheet will report the number of days that ...

how to save a resource
Hello, my program creates for example a PHP script file. So I can crete a file by CFile and than use CFile::Write method. It's clear. But because this file is quite long, I had this idea. Save this file to resources and when I will need create this file, just load this file from resources and save it to disk. Is it possible? I really do not how :-( Thank you for your advice Robert See Using Text File Resources in VC++ By DGoins http://www.codeproject.com/cpp/usingtextfile_resources.asp -- Un saludo Rodrigo Corral Gonz�lez [MVP] microsoft.public.es.vc FAQ http://vcfaq.europe.w...

open/save dialog title broken
The title bar of any Office 2003 program's open/save dialog has just a single letter. Any ideas what's broken? tbone ...

Help With Strange Error When Trying to Save Any Record
I am getting astrane error happens when try to create any new record (Customer, Item, Vendor or Account), the system gives me a message that "Save Operation Failed" and when i click "More Info" the error message is "Could not find stored procedure 'DYNAMICS.dbo.aagGetCompanyStatus'", although i have created alot of items, customers, accounts and vendors before but suddenly this error appeared. Any quick help will be highly appreciated. It would appear that the AAG has something to do with a product produced by American Association of Geographers. I...

question about using the correct schema namespace
I have a Access/VBA client that exports xml to the local drive, then posts it over http to an aspx page. The aspx page consumes it, then builds itself based on the xml data. This works find only if I first mannually change the root entry's namespace url as shown below. Does anyone know how I can get the two (cleint xml export and aspx xml consume) to work together with the appropriate namespace? Here is the top three lines of my xml export (prior to mannually changing it): <?xml version="1.0" encoding="UTF-8"?> <root xmlns:xsd="http://www.w3.org/200...

AD/Network design question
Hello all I have a 2 sites which users come and go from. These sites have 2 different network ip domains (192.168.1.x and 192.168.2.x). Users need to be authenticated using the same user id and password at both sites. DC/GC is at 192.168.1.x and is a SBS 2003. Server at 192.168.2.x is Server 2003. When the server at 192.168.2.x is connected via vpn to 192.168.1.x all is well. How do I get the server at 192.168.2.x to act as a AD/DC when it’s not connected to 192.168.1.x ? Thank you Hal I think you will run here into the limitations of SBS :-( @ SBS experts : ...

Mail merge & staple question
Does anyone know how to use mail merge in Publisher with a printer that folds and staples?? Publisher is sending it to the printer as "one" big file and trying to staples "all" my newsletters together instead of individual ones with the addresses on them. Or if anyone has any other programs or ideas on how I can accomplish this task, sure would be appreciated. Thanks While waiting for decisions from his 6 university choices, Ed sees a message from Parishsecretary <Parishsecretary@discussions.microsoft.com>. On it is written: > Does anyone know how to use mai...

Error saving a Shared Workbook
I have a user using a shared workbook and gets an error everytime she does this ONE specific change. She deletes a line and then saves and gets a message that says, "EXCEL.exe has generated errors and will be shutdown by Windows... blah blah blah". If she makes anyother type of changes it saves just fine. I also had another user do the SAME change and that person also got that error message. When the file is changed to "Not Shared" then the line is deleted it saves fine also. The problem is obviously with the file itself and that is shared out. can anybody ...

Office 2010 Buying Question Assistance Needed
I've been looking through the MS Office 2010 web site to try to determine what my new small company would require, but I can't find the information I need. We for sure would need Office Pro Plus, but other than that I'm not sure. We want to run it on our own server. We will initially have 3-5 people using it and perhaps more later on. Would we need to purchase site licensing? Unfortunately, our programmers are MS haters (I'm not) and I can't get any assistance from them on this, but I have power of the pen. I would appreciate any assistance I can get. Th...

Question About Missing Data
So, this is probably really easy, but I just want to ask and see if I may be missing something here. Some data on vendor numbers changed. Let’s say IBM used to have a vendor number 12345 and now it’s vendor number is 56789. I can identify IBM as IBM, but I really want to use the number, not the name. Should I set up a table that ties the numbers together, so that Access knows 12345 = 56789? Or, should I do some kind of Update Query and change all incidences of 12345 to be 56789? Or, is there some other, method, like a ‘best practices for missing data’? Thanks! Ryan--- ...

Custom CRect Question
I have a custom rectangle class that inherits from CRect: class CCustomRect : public CRect { private: CPoint m_maxPt; COLORREF m_color; TCHAR text[50]; public: CCustomRect(RECT* source, CPoint pt, COLORREF rgb); RECT* RectBase(); void Update(RECT* r); } Inheritance has worked well until I found myself needing to create the RectBase function (above) to return the rectangle dimensions. CRect does not seem to have any methods that can be called to return the base class's RECT value. I could take CRect::Size and construct a rectangle to return, but this seems a bit much. My...

Excel link update question
I need to maintain an excel workbook which contains a lot of links to other workbooks. Since the linked workbooks change every week, I need to change all the links accordingly. For example, a cell with formula "='[aug_28.xls]sheet1' !A10" will be changed into "='[sep_4.xls]sheet1'!A10". I tried to do this with Find/Replace. However, the link is updated every time it is changed. The link updating takes a couple of seconds. So it may take a hour to finsh it for a workbook with thousands of links. Could anyone tell me how to shut down the link updating when...

save imbedded pictures
Got a question... If I try to right-click/SAVE a picture in an Outlook email the format defaults to BMP even if it's something else such as an animated GIF. There is a fix for a similar image save error in IE6 but I can't find a repair for this in Outlook. http://support.microsoft.com/?kbid=810978 addresses exactly this issue in IE6. Does anyone know of a similar fix for Outlook? I would love to be able to pull images from my messages without having to forward them to an account pointed to Outlook Express (which will extract images correctly on my system). Thanks in advance! ...

Save as Excel from Master Project
I am trying to export from a master project with about 8 sub- projects. When I try and export from the master to excel, it does not include certain text fields. Why? Any work arounds? I need the text field (name) to use the excel sheet. How are you exporting? Data lives in the sub-projects, not the master. However, try expanding all sub-projects and try again Not all custom fields roll up to the sub-project tasks, so their data is not available in the master. For this and other reasons (including no risk of file corruption) I usually create new masters every week but no...

VS 2005 beta question
All, I need to complie some code. I am going from 16bit to 64 bit. The job do not want to spend the money on VS 2005.net. If I compile the code with the beta version or trial version of VS 2005.NET will it time bomb on me? Thanks in advance The code won't, but eventually the compiler will stop working. Don't know if the trial will support 64 bit though. I guess you get what you pay for. Tom "karibbean" <sharp_mind@REMOVE.this.email.msn.dotcom> wrote in message news:%23OyZFNUFGHA.1124@TK2MSFTNGP10.phx.gbl... > All, > > I need to complie some cod...

Payables, Financial Batch and other questions
Please bear with me I have a lot of questions and the help of those who are experienced and knowledgeable would be well appreciated. Thanks. MISSING TABLES 1. I ran hotfix for GP9 but I decided not anymore to continue with it because there were other requirements. Thus, I reinstalled the applicaiton GP9 and restored my backup dynamics & company database. There were tables that were lost when I restored it. I just want to know how to copy the tables to my current database. Most of the tables that were lost were from the Cashbook (i.e. CB900045, CB200001) and other tables such as SY...

prompting to save workbook every time (even when no changes made)
i have 3 workbooks all very similar and every single time i open any o them, even when not changing anything, i am prompted to save th thing. its so bad that i can literally open the workbook then click the clos button straight away and it STILL prompts me to save it because i seems to think something has changed. as far as i can see i dont have any macros or anything that will ru every time it starts and change something (i did have a = today in on cell which kept the date as today but taking this out made n difference -- Message posted from http://www.ExcelForum.com Hi Neowok! You prob...

Why do my questions get deleted sometimes?
Apologies, I have posted this on the worksheet functions group too... I love the feedback I get from these groups, but every now and then, my messages get deleted. I'd like to know what I'm doing wrong. Many of my messages ARE posted and answered, and I'm grateful for that, but one or two get removed - regardless of how often I post them. I don't swear or say anything bad about Excel - I love it. So why don't they get posted are there some words or subjects that I should avoid? Will this one get deleted - it's a bit off subject? But I'd love to have an ans...

Named ranges
Excel 2003 I have a total sheet that gets data from three different shift sheets (all in the same workbook) for a monthly report. I have named ranges on each shift sheet for each month's production data (S1M1, S1M2, S1M3, S2M1...) where S1M1 =A2:AC147, S1M2 = A148:AC329, etc. The old formula was:=SUMIF('SHIFT 1'!$L$1:$L$147,"BB",'SHIFT 1'!$T$1:$T$147). I'm stumped as to what the new formula would be - how would I direct Excel to column L of S1M1 to search for "BB", then add the contents of column T? The range changes each month, and I tho...

Serializing array of userdefined types
Hello, I want to have a class that contains only a collection of another class. For example: public __gc class Alignment { public: Alignment(); ... }; // Probably using XmlIncludeAttribute such as this is wrong... [System::Xml::Serialization::XmlIncludeAttribute(__typeof(Alignment))] public __gc class Alignments : public System::Collections::ArrayList { public: Alignments(); ... }; I figured I could use Alignments like this: Alignment* alignment = new Alignment; Alignments* alignments = new Alignments; alignments->Add(alignment); BTW, I am using XmlSerializer and XmlTextWriter....