VBでArrayIndexを検査するSetter/Getter
Option Explicit Private Function MySize(ByRef a As Variant) As Long MySize = UBound(a) End Function Private Function MyGet(ByRef a As Variant, ByVal i As Long) If LBound(a) <= i And i <= UBound(a) - 1 Then MyGet = a(i) Else Call Err.Raise(50000) End If End Function Private Sub MySet(ByRef a As Variant, ByVal i As Long, ByVal v As Variant) If LBound(a) <= i And i <= UBound(a) - 1 Then a(i) = v Else Call Err.Raise(50000) End If End Sub Private Sub Command1_Click() Dim a() As String Dim i As Long Dim t As Long ReDim a(10) For i = 0 To MySize(a) - 1 Call MySet(a, i, i + 100) Next For i = 0 To MySize(a) - 1 t = MyGet(a, i) Debug.Print "a(" & i & ") = " & a(i) Next End Sub
でどうだ?