LBound, UBound Properties Example

This example prints the values of these two properties for a control array. Put an OptionButton control on a form, and set its Index property to 0 (to create a control array). To try this example, paste the code into the Declarations section of a form, and then press F5 and click the form.

Private Sub Form_Paint ()
   Static FlagFormPainted As Integer
   If FlagFormPainted <> True Then ' When form is painting for first time,
      For i = 1 To 3
         Load Option1(i)   ' add three option buttons to array.
         Option1(i).Top = Option1(i - 1).Top + 350
         Option1(i).Visible = True
      Next I
      For I =  0 to 3   ' Put captions on the option buttons.
         Option1(i).Caption = "Option #" & CStr(i)
      Next I
      Option1(0).Value = True   ' Select first option button.
      FlagFormPainted = True   ' Form is done painting.
   End If
End Sub
Private Sub Form_Click ()
   Print "Control array's Count property is " & Option1().Count
   Print "Control array's LBound property is " & Option1().LBound
   Print "Control array's UBound property is " & Option1().UBound
End Sub