I have a split function that returns two strings implicitly. I want to execute a piece of code if position one of the returned variant contains data. However I can’t seem to formulate the right IF/Then statement to validate that.
I have:
If variantVariable(1) <> “” Then
End If
However, that still throws the ‘subscript out of range’ error because that position never gets populated.
Any thoughts?
thanks,
Shawn
Subject: Catch a subscript out of reange error
Why not check to see if the variant is an array and then get the bounds of the array and use those?
From the help:
Dim arrayFixed(1 To 5)
Dim arrayDynam()
Print IsArray(arrayFixed) ’ Output: True
Print IsArray(arrayDynam) ’ Output: True
Dim v As Variant
Print IsArray(v) ’ Output: False
v = arrayFixed
Print IsArray(v) ’ Output: True
You could split the strings and then take your return variant, and check to see if it is an array and if so, perform the validation (also, make sure variantVariable(1) is a string if you’re checking for “”, else use the appropriate check (isEmpty for a variant, 0 for an integer, and so on).
Subject: Catch a subscript out of reange error
You could set OnError GoTo NullArray Then if Array(N) is not valid then focus is passed to NullArray (or whatever you call it) now you know that the the position is invalid. The OnError traps the error and passes control to the Label defined.
Not necessarily pretty but it will work.
Subject: RE: Catch a subscript out of reange error
Thanks Guys,
Shawn