0

I am getting an error that says: Subscript out of range: '[number: 8]'

I just want to add something like this:

//if not RowArray(8) out of range then
// kill yourself at RowArray(8)
//else
// kill yourself now
//end if

The killing part is a joke :)

Thanks

Solid1Snake1
  • 272
  • 1
  • 6
  • 22

1 Answers1

0

UBound and LBound will let you determine if a given index is a valid choice within a VBScript array.

function GetNumberEight
  If UBound(RowArray) > 8 Then
    GetNumberEight = ""
  else
    GetNumberEight = RowArray(8)
  end if
end function

If you need to specifically get one number from an array, though, you may want to consider refactoring your code. Eight variable declarations, or eight properties of a data object, will not run significantly slower than an eight member array.

(And if it's VB.NET, consider using the other .NET collection classes.)

DougM
  • 2,808
  • 17
  • 14
  • @DougM - the condition is wrong, a function returning a number or a string is an abomination, using 'numbered variables' instead of a collecting is a design flaw, neither a variable nor another collection will spare the check whether there is a usable value: -1. – Ekkehard.Horner May 17 '13 at 06:31
  • -1 is a number, not a "no number found." That's what null (and Nothing) is for. And, yeah, don't design arrays this way. Even in VB Script you have a `Scripting.Dictionary` available. – DougM May 17 '13 at 14:23