BorlandTalk.com Forum Index BorlandTalk.com
Borland discussion newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

VarArrayCreate

 
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> Delphi OLE Automation
View previous topic :: View next topic  
Author Message
Uncle Potato
Guest





PostPosted: Fri Aug 05, 2005 7:20 am    Post subject: VarArrayCreate Reply with quote



I am trying to manipulate a column of excel data
I do
Data := varArrayCreate([7,5822,1,1], varVariant);
Data := ExcellApp.Range('A7:A5822').Value;

It runs without error
However, when I do a
For K:= 7 to 5822 do
Begin
Data[K,1] := something;
End

I hit into an index out of bounds.
The help on vararrayCreate(...)
says "The Bounds parameter specifies the upper and lower bounds of one
dimension of the array (in pair)"
So I guess 7,5822 means the array is from 7 through 5822 ??
In fact, I found out that Data[1,1] is still valid, while Data[0,1] is
not. Data[5822,1] is out of bound, while the last one is
Data[5822-5,1], which I don't quite understand.

Am I reading the help wrong ? Or any other issue ?

Back to top
Avatar Zondertau
Guest





PostPosted: Fri Aug 05, 2005 7:34 am    Post subject: Re: VarArrayCreate Reply with quote



Quote:
I am trying to manipulate a column of excel data
I do
Data := varArrayCreate([7,5822,1,1], varVariant);
Data := ExcellApp.Range('A7:A5822').Value;

It runs without error
However, when I do a
For K:= 7 to 5822 do
Begin
Data[K,1] := something;
End

I hit into an index out of bounds.
The help on vararrayCreate(...)
says "The Bounds parameter specifies the upper and lower bounds of one
dimension of the array (in pair)"
So I guess 7,5822 means the array is from 7 through 5822 ??
In fact, I found out that Data[1,1] is still valid, while Data[0,1] is
not. Data[5822,1] is out of bound, while the last one is
Data[5822-5,1], which I don't quite understand.

Am I reading the help wrong ? Or any other issue ?

Yes, you're reading the wrong help. The value returned by
VarArrayCreate is completely irrelevant here, because it's overwritten
by the Excel range. I think (but you should look this up in the Excel
help file) that arrays returned by Excel always use indices starting at
one, which would mean:

A7 => Data[1]
A8 => Data[2]
....
A5822 => Data[5814]

Just remove the VarArrayCreate here and take a look at Excel's help (on
MSDN) to see why the bounds are not as you expect.

Back to top
Nikolay
Guest





PostPosted: Fri Aug 05, 2005 7:59 am    Post subject: Re: VarArrayCreate Reply with quote




Hi

Ferther, since we are not sure which is the starting and
which is the ending point of the VALUE variant array
returned by the EXCEL.RANGE function we may use :

VarArrayGet function that accepts as a first
parameter the array and as a second parameter
the number of the element assuming 0 base.

For example

VarArrayGet(Data,[3]); in your case shoudl return
A4

Please note that this is a variant because we are not
sure of the type entered in A4.

Nikolay

"Avatar Zondertau" <avatarzt (AT) gmail (DOT) com (please reply to newsgroup)> wrote:
Quote:
I am trying to manipulate a column of excel data
I do
Data := varArrayCreate([7,5822,1,1], varVariant);
Data := ExcellApp.Range('A7:A5822').Value;

It runs without error
However, when I do a
For K:= 7 to 5822 do
Begin
Data[K,1] := something;
End

I hit into an index out of bounds.
The help on vararrayCreate(...)
says "The Bounds parameter specifies the upper and lower bounds of one
dimension of the array (in pair)"
So I guess 7,5822 means the array is from 7 through 5822 ??
In fact, I found out that Data[1,1] is still valid, while Data[0,1] is
not. Data[5822,1] is out of bound, while the last one is
Data[5822-5,1], which I don't quite understand.

Am I reading the help wrong ? Or any other issue ?

Yes, you're reading the wrong help. The value returned by
VarArrayCreate is completely irrelevant here, because it's overwritten
by the Excel range. I think (but you should look this up in the Excel
help file) that arrays returned by Excel always use indices starting at
one, which would mean:

A7 => Data[1]
A8 => Data[2]
...
A5822 => Data[5814]

Just remove the VarArrayCreate here and take a look at Excel's help (on
MSDN) to see why the bounds are not as you expect.


Back to top
Uncle Potato
Guest





PostPosted: Fri Aug 05, 2005 9:57 am    Post subject: Re: VarArrayCreate Reply with quote

Quote:
VarArrayCreate is completely irrelevant here, because it's overwritten
by the Excel range.
arrays returned by Excel always use indices starting at 1

Oh.... That means VarArrayCreate is not actually needed
The ExcelApp.Range['A1:Z100'].Value would create it for me.
Strage, I read off the web quite a number of times that others are
writing it this way.
Thanks!


On 5 Aug 2005 00:59:53 -0700, "Nikolay" <shemet (AT) mbox (DOT) contact.bg>
wrote:
Quote:
Ferther, since we are not sure which is the starting and
which is the ending point of the VALUE variant array
returned by the EXCEL.RANGE function

Mm.... Isn;t that I have to give what range of cells I need? Then, in
what case that the number of member is unknown?

Quote:
we may use :
VarArrayGet function that accepts as a first
parameter the array and as a second parameter
the number of the element assuming 0 base.

For example
VarArrayGet(Data,[3]); in your case shoudl return
A4

Nikolay

I am completely lost here.

From help :
"Returns a Variant that represents a single value from a
multi-dimensional Variant array "

To get a *single* value from an array, why don't I simply do a
Data[a,b] directly??

Just a wild guess, VarArrayGet creates another array from a array
with member selection from the list ?

Array2 := varArrayGet(Arr1, [ 0,1]); returns the first two ??


Back to top
Nikolay
Guest





PostPosted: Sun Aug 07, 2005 7:42 am    Post subject: Re: VarArrayCreate Reply with quote


Yes that's right, I am sorry I fearther noticed your Delphi version I am doing all that with delphi 7 but still the things I wrote may work with D6



Nikolay

Uncle Potato <Potato (AT) aelhk (DOT) com> wrote:
Quote:
VarArrayCreate is completely irrelevant here, because it's overwritten
by the Excel range.
arrays returned by Excel always use indices starting at 1

Oh.... That means VarArrayCreate is not actually needed
The ExcelApp.Range['A1:Z100'].Value would create it for me.
Strage, I read off the web quite a number of times that others are
writing it this way.
Thanks!


On 5 Aug 2005 00:59:53 -0700, "Nikolay" wrote:
Ferther, since we are not sure which is the starting and
which is the ending point of the VALUE variant array
returned by the EXCEL.RANGE function

Mm.... Isn;t that I have to give what range of cells I need? Then, in
what case that the number of member is unknown?

we may use :
VarArrayGet function that accepts as a first
parameter the array and as a second parameter
the number of the element assuming 0 base.

For example
VarArrayGet(Data,[3]); in your case shoudl return
A4

Nikolay

I am completely lost here.
From help :
"Returns a Variant that represents a single value from a
multi-dimensional Variant array "

To get a *single* value from an array, why don't I simply do a
Data[a,b] directly??

Just a wild guess, VarArrayGet creates another array from a array
with member selection from the list ?

Array2 := varArrayGet(Arr1, [ 0,1]); returns the first two ??



Back to top
Display posts from previous:   
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> Delphi OLE Automation All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.