Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
baj baj is offline
external usenet poster
 
Posts: 24
Default How to view the dimension of an open array in VBA ?

Hi All,
Suppose you create an open array (1 dimension) :
Dim arr() as String

Then functions like Ubound(arr) or Lbound(arr) will give an error on
the subscript...

With which function or method is it possible to know if the array arr
has got some dimensions or not ?
I want to know this because I want enlarge the array when I need it...
that's not diffcult with the combination 'Preserve Redim' but I have to
know the starting point...

If arr() has just been dimensioned and you want to add 3 elements then
you have to Redim arr(3),
But when arr() has already 5 elements you have to say Preserve Redim
arr(8)

One should expect you can check this dimension with Ubound or LBound...
but this isn't the case if the dimension is actualy not existing...

How, How ?

TXS for any help

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 789
Default How to view the dimension of an open array in VBA ?

Hi
Hard to see why you would check the size of an array without declaring
its size first...maybe your code sequencing needs a rethink?
That said, how about

on error resume next
err.clear
ArraySize = UBound(arr)
If err.number<0 then
'the redim bit
Else
'the dim bit
end if
on error goto 0

regards
Paul

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default How to view the dimension of an open array in VBA ?

redim preserve arr(lbound(arr) to ubound(arr)+3)

????



baj wrote:

Hi All,
Suppose you create an open array (1 dimension) :
Dim arr() as String

Then functions like Ubound(arr) or Lbound(arr) will give an error on
the subscript...

With which function or method is it possible to know if the array arr
has got some dimensions or not ?
I want to know this because I want enlarge the array when I need it...
that's not diffcult with the combination 'Preserve Redim' but I have to
know the starting point...

If arr() has just been dimensioned and you want to add 3 elements then
you have to Redim arr(3),
But when arr() has already 5 elements you have to say Preserve Redim
arr(8)

One should expect you can check this dimension with Ubound or LBound...
but this isn't the case if the dimension is actualy not existing...

How, How ?

TXS for any help


--

Dave Peterson
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 225
Default How to view the dimension of an open array in VBA ?

My usual technique in this situation is to force arr to be an
"empty array" by using:

arr = split("")

This makes UBound(arr) = -1, so you test for this to see
if arr contains any data yet.

hth
Andrew


baj wrote:
Hi All,
Suppose you create an open array (1 dimension) :
Dim arr() as String

Then functions like Ubound(arr) or Lbound(arr) will give an error on
the subscript...

With which function or method is it possible to know if the array arr
has got some dimensions or not ?
I want to know this because I want enlarge the array when I need it...
that's not diffcult with the combination 'Preserve Redim' but I have to
know the starting point...

If arr() has just been dimensioned and you want to add 3 elements then
you have to Redim arr(3),
But when arr() has already 5 elements you have to say Preserve Redim
arr(8)

One should expect you can check this dimension with Ubound or LBound...
but this isn't the case if the dimension is actualy not existing...

How, How ?

TXS for any help


  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 783
Default How to view the dimension of an open array in VBA ?

baj wrote:
Hi All,
Suppose you create an open array (1 dimension) :
Dim arr() as String

Then functions like Ubound(arr) or Lbound(arr) will give an error on
the subscript...

With which function or method is it possible to know if the array arr
has got some dimensions or not ?
I want to know this because I want enlarge the array when I need it...
that's not diffcult with the combination 'Preserve Redim' but I have to
know the starting point...

If arr() has just been dimensioned and you want to add 3 elements then
you have to Redim arr(3),
But when arr() has already 5 elements you have to say Preserve Redim
arr(8)

One should expect you can check this dimension with Ubound or LBound...
but this isn't the case if the dimension is actualy not existing...

How, How ?

TXS for any help

If the functions in the freely downloadable file at
http://home.pacbell.net/beban are available to your workbook, then

ArrayDimensions(arr) will return 0 if the array has not yet been sized.

Alan Beban


  #6   Report Post  
Posted to microsoft.public.excel.programming
baj baj is offline
external usenet poster
 
Posts: 24
Default How to view the dimension of an open array in VBA ?

Hi,

Many Thanks to all the contributors to answering my question.

Baj

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Mutli-dimensional Array to Single-Dimension Array Blue Aardvark Excel Programming 3 October 15th 05 09:22 AM
Array transfer - 1 dimension v. 2 dimension JWolf[_2_] Excel Programming 2 June 29th 04 01:02 AM
Getting excel array dimension banavas[_3_] Excel Programming 3 June 8th 04 12:11 PM
Applying Sum Function to 2nd Dimension of Array ExcelMonkey[_36_] Excel Programming 2 January 28th 04 05:48 PM
single dimension array RobcPettit Excel Programming 3 January 20th 04 08:33 AM


All times are GMT +1. The time now is 05:38 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"