LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 87
Default Handling ubound on an uninitialised array

Two part question....

I have the following code driver to show the example

The Links array will have been populated with values
I then want to call my Filter subroutine, to find links which match
sFilter, and add them to the Target array - called filter

The code below works, but I'd like to avoid the "On error" if I could.
In the debugger I see first time in that sTarget has a value of Nothing,
but I can't work out how to test for this. Both
if sTarget is Nothing and
if sTarget() is Nothing
fail. What do I need to do to solve this

Option Explicit
Option Base 1

Type LinkInfo
href As String
InnerText As String
End Type

Dim Links() As LinkInfo
Dim Filtered() As LinkInfo
Sub Setup()

ReDim Links(4)
Links(1).href = "AAAAA"
Links(2).href = "ABBBA"
Links(3).href = "AAACCC"
Links(4).href = "ADDDA"

Filter Links, Filtered, "AA"
Filter Links, Filtered, "DDD"
Links(4).href = "ADDDA"

End Sub
Sub Filter(sSource() As LinkInfo, sTarget() As LinkInfo, sFilter As
String)

Dim iIndex As Integer
Dim iLength As Integer

On Error Resume Next
iLength = UBound(sTarget)
On Error GoTo 0

For iIndex = 1 To UBound(sSource)
If sSource(iIndex).href Like "*" & sFilter & "*" Then
iLength = iLength + 1

If iLength = 1 Then
ReDim sTarget(1)
Else
ReDim Preserve sTarget(iLength)
End If

sTarget(iLength) = sSource(iIndex)
End If
Next

End Sub


Part Two...
Suppose Filtered() was a global variable.
How would I "clear it down" so that I could manipulate a further set of
links and effectively start over?
The only code that will work is
ReDim Filtered(1)


so I suppose all of the above is going to point to me using an option
base of 0 - and wasting that element of the array. This will then
provide a solution for my uninitialised array in my Filter routine. Is
that what you reckon?
--
Mike
Please post replies to newsgroup to benefit others
Replace dead spam with ntl world to reply by email
 
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
Why is this returning a Ubound value of zero [email protected] Excel Discussion (Misc queries) 1 September 28th 07 07:44 PM
multiple file uploading - runtime error'13': type mismatch "While Counter <= UBound(FName)" Sinner Excel Discussion (Misc queries) 3 March 1st 07 09:44 AM
UBound not in Intellisense. References problem? Stephen Rasey[_2_] Excel Programming 3 September 27th 04 12:08 AM
error handling off?? Tom Ogilvy Excel Programming 0 August 19th 04 04:31 PM
Ubound & Lbound Michael168[_80_] Excel Programming 3 June 1st 04 02:00 PM


All times are GMT +1. The time now is 09:03 AM.

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

About Us

"It's about Microsoft Excel"