Home |
Search |
Today's Posts |
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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 |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Conditional Testing of an array | Excel Worksheet Functions | |||
Testing same cell across multiple sheets for a string and counting each instance? | Excel Worksheet Functions | |||
Passing a String in Array to Range as String | Excel Programming | |||
Fill an Array with String values | Excel Programming | |||
Variant Array with String Values - Type Mismatch | Excel Programming |