Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10
Default Testing a string array for any values

Hi,
I have a dynamic, zero-based, string array that I Redim
often, and i want to know how do i test it to see if it
actually has any elements in it before I put it thru the
loop to extract the data. If I have no elements I want to
exit before looping. Can I use IsEmpty to test a string
Array or is it a "" value by default. I forget, and
documentation is sparse on details.

thank you

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Testing a string array for any values

Based on the limited description of the situation I believe you would have
to loop through each element and compare it to a null string ("")

Since you have redim'd the array and haven't erased it, I don't think you
can check for anything against the array variable itself

If you have erased it that would be a different situation.

--
Regards,
Tom Ogilvy



"Chris W." wrote in message
...
Hi,
I have a dynamic, zero-based, string array that I Redim
often, and i want to know how do i test it to see if it
actually has any elements in it before I put it thru the
loop to extract the data. If I have no elements I want to
exit before looping. Can I use IsEmpty to test a string
Array or is it a "" value by default. I forget, and
documentation is sparse on details.

thank you



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default Testing a string array for any values

Chris,

You could try

If Application.CountA(ary) 0 Then
'process it
End If

it will fail if there are strings or numbers.

--

HTH

RP
(remove nothere from the email address if mailing direct)


"Chris W." wrote in message
...
Hi,
I have a dynamic, zero-based, string array that I Redim
often, and i want to know how do i test it to see if it
actually has any elements in it before I put it thru the
loop to extract the data. If I have no elements I want to
exit before looping. Can I use IsEmpty to test a string
Array or is it a "" value by default. I forget, and
documentation is sparse on details.

thank you



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,758
Default Testing a string array for any values

I don't think this will work with string arrays:

Dim myArray() As String
ReDim myArray(1 To 5)
MsgBox Application.CountA(myArray)

I got 5 back in the msgbox.



Bob Phillips wrote:

Chris,

You could try

If Application.CountA(ary) 0 Then
'process it
End If

it will fail if there are strings or numbers.

--

HTH

RP
(remove nothere from the email address if mailing direct)

"Chris W." wrote in message
...
Hi,
I have a dynamic, zero-based, string array that I Redim
often, and i want to know how do i test it to see if it
actually has any elements in it before I put it thru the
loop to extract the data. If I have no elements I want to
exit before looping. Can I use IsEmpty to test a string
Array or is it a "" value by default. I forget, and
documentation is sparse on details.

thank you


--

Dave Peterson
  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Testing a string array for any values

Good catch. It would work if the array were variant, but a string array in
initialized to "" for each element I believe.

--
Regards,
Tom Ogilvy

"Dave Peterson" wrote in message
...
I don't think this will work with string arrays:

Dim myArray() As String
ReDim myArray(1 To 5)
MsgBox Application.CountA(myArray)

I got 5 back in the msgbox.



Bob Phillips wrote:

Chris,

You could try

If Application.CountA(ary) 0 Then
'process it
End If

it will fail if there are strings or numbers.

--

HTH

RP
(remove nothere from the email address if mailing direct)

"Chris W." wrote in message
...
Hi,
I have a dynamic, zero-based, string array that I Redim
often, and i want to know how do i test it to see if it
actually has any elements in it before I put it thru the
loop to extract the data. If I have no elements I want to
exit before looping. Can I use IsEmpty to test a string
Array or is it a "" value by default. I forget, and
documentation is sparse on details.

thank you


--

Dave Peterson





  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,758
Default Testing a string array for any values

That's what I saw when I had a watch on that variable.

And I think it depends on what you call elements...

Option Explicit
Sub testme()
Dim myArray() As Variant
Dim iCtr As Long
ReDim myArray(1 To 5)
MsgBox Application.CountA(myArray)
For iCtr = LBound(myArray) To UBound(myArray)
myArray(iCtr) = Empty
Next iCtr
MsgBox Application.CountA(myArray)
End Sub

If I stick Empty in the array's elements, is it being used?

If no, then I like Bob's response.

If yes, then I don't like Bob's response.





Tom Ogilvy wrote:

Good catch. It would work if the array were variant, but a string array in
initialized to "" for each element I believe.

--
Regards,
Tom Ogilvy

"Dave Peterson" wrote in message
...
I don't think this will work with string arrays:

Dim myArray() As String
ReDim myArray(1 To 5)
MsgBox Application.CountA(myArray)

I got 5 back in the msgbox.



Bob Phillips wrote:

Chris,

You could try

If Application.CountA(ary) 0 Then
'process it
End If

it will fail if there are strings or numbers.

--

HTH

RP
(remove nothere from the email address if mailing direct)

"Chris W." wrote in message
...
Hi,
I have a dynamic, zero-based, string array that I Redim
often, and i want to know how do i test it to see if it
actually has any elements in it before I put it thru the
loop to extract the data. If I have no elements I want to
exit before looping. Can I use IsEmpty to test a string
Array or is it a "" value by default. I forget, and
documentation is sparse on details.

thank you


--

Dave Peterson


--

Dave Peterson
  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,588
Default Testing a string array for any values

if join(arrayName,"")="" then
'do stuff
end if

Tim


"Chris W." wrote in message
...
Hi,
I have a dynamic, zero-based, string array that I Redim
often, and i want to know how do i test it to see if it
actually has any elements in it before I put it thru the
loop to extract the data. If I have no elements I want to
exit before looping. Can I use IsEmpty to test a string
Array or is it a "" value by default. I forget, and
documentation is sparse on details.

thank you



  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default Testing a string array for any values

Spot on Dave. It assumes variant (there was an implicit giveaway in my
comment that it would fail if there are strings or numbers :-)).

Bob

--

HTH

RP
(remove nothere from the email address if mailing direct)


"Dave Peterson" wrote in message
...
I don't think this will work with string arrays:

Dim myArray() As String
ReDim myArray(1 To 5)
MsgBox Application.CountA(myArray)

I got 5 back in the msgbox.



Bob Phillips wrote:

Chris,

You could try

If Application.CountA(ary) 0 Then
'process it
End If

it will fail if there are strings or numbers.

--

HTH

RP
(remove nothere from the email address if mailing direct)

"Chris W." wrote in message
...
Hi,
I have a dynamic, zero-based, string array that I Redim
often, and i want to know how do i test it to see if it
actually has any elements in it before I put it thru the
loop to extract the data. If I have no elements I want to
exit before looping. Can I use IsEmpty to test a string
Array or is it a "" value by default. I forget, and
documentation is sparse on details.

thank you


--

Dave Peterson



  #9   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Testing a string array for any values

since he said:
I have a dynamic, zero-based, string array


guess you should have stated it more directly.

--
Regards,
Tom Ogilvy

"Bob Phillips" wrote in message
...
Spot on Dave. It assumes variant (there was an implicit giveaway in my
comment that it would fail if there are strings or numbers :-)).

Bob

--

HTH

RP
(remove nothere from the email address if mailing direct)


"Dave Peterson" wrote in message
...
I don't think this will work with string arrays:

Dim myArray() As String
ReDim myArray(1 To 5)
MsgBox Application.CountA(myArray)

I got 5 back in the msgbox.



Bob Phillips wrote:

Chris,

You could try

If Application.CountA(ary) 0 Then
'process it
End If

it will fail if there are strings or numbers.

--

HTH

RP
(remove nothere from the email address if mailing direct)

"Chris W." wrote in message
...
Hi,
I have a dynamic, zero-based, string array that I Redim
often, and i want to know how do i test it to see if it
actually has any elements in it before I put it thru the
loop to extract the data. If I have no elements I want to
exit before looping. Can I use IsEmpty to test a string
Array or is it a "" value by default. I forget, and
documentation is sparse on details.

thank you


--

Dave Peterson





  #10   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default Testing a string array for any values

Guess I should.


"Tom Ogilvy" wrote in message
...
since he said:
I have a dynamic, zero-based, string array


guess you should have stated it more directly.

--
Regards,
Tom Ogilvy

"Bob Phillips" wrote in message
...
Spot on Dave. It assumes variant (there was an implicit giveaway in my
comment that it would fail if there are strings or numbers :-)).

Bob

--

HTH

RP
(remove nothere from the email address if mailing direct)


"Dave Peterson" wrote in message
...
I don't think this will work with string arrays:

Dim myArray() As String
ReDim myArray(1 To 5)
MsgBox Application.CountA(myArray)

I got 5 back in the msgbox.



Bob Phillips wrote:

Chris,

You could try

If Application.CountA(ary) 0 Then
'process it
End If

it will fail if there are strings or numbers.

--

HTH

RP
(remove nothere from the email address if mailing direct)

"Chris W." wrote in message
...
Hi,
I have a dynamic, zero-based, string array that I Redim
often, and i want to know how do i test it to see if it
actually has any elements in it before I put it thru the
loop to extract the data. If I have no elements I want to
exit before looping. Can I use IsEmpty to test a string
Array or is it a "" value by default. I forget, and
documentation is sparse on details.

thank you


--

Dave Peterson







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
Conditional Testing of an array Lord Robocop Excel Worksheet Functions 1 May 7th 09 03:22 AM
Testing same cell across multiple sheets for a string and counting each instance? [email protected] Excel Worksheet Functions 5 March 8th 07 02:57 PM
Passing a String in Array to Range as String [email protected] Excel Programming 2 September 1st 04 01:13 AM
Fill an Array with String values John Michl[_2_] Excel Programming 6 May 14th 04 07:10 PM
Variant Array with String Values - Type Mismatch jamiee Excel Programming 2 March 7th 04 03:39 AM


All times are GMT +1. The time now is 01:56 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"