G
Greg
I don't understand the results that I am seeing with a UBound process.
It seems that the value is 1 greater than it should be.
Can anyone explain to me why the last three message boxes in the code
below are returning the result they do? Thank you.
Sub Test()
Dim oFld As FormField
Dim oFldDDArray() As String
Dim numEntries As Integer
Dim i As Integer
Dim a As Integer
Dim z As Integer
'I have a Dropdown formfield with 5 entries
Set oFld = Selection.FormFields(1)
numEntries = oFld.DropDown.ListEntries.Count
MsgBox numEntries 'Returns 5
ReDim oFldDDArray(numEntries)
For i = 1 To numEntries
'Add entries to array
oFldDDArray(i - 1) = oFld.DropDown.ListEntries(i).Name
Next i
a = LBound(oFldDDArray)
MsgBox a 'Returns 0
MsgBox oFldDDArray(a) 'returns first item in array
z = UBound(oFldDDArray)
MsgBox z 'Returns 5. Why? Only 5 items in the array (0-4)
MsgBox oFldDDArray(z) 'Empty
MsgBox oFldDDArray(z - 1) 'Returns last item in array
End Sub
It seems that the value is 1 greater than it should be.
Can anyone explain to me why the last three message boxes in the code
below are returning the result they do? Thank you.
Sub Test()
Dim oFld As FormField
Dim oFldDDArray() As String
Dim numEntries As Integer
Dim i As Integer
Dim a As Integer
Dim z As Integer
'I have a Dropdown formfield with 5 entries
Set oFld = Selection.FormFields(1)
numEntries = oFld.DropDown.ListEntries.Count
MsgBox numEntries 'Returns 5
ReDim oFldDDArray(numEntries)
For i = 1 To numEntries
'Add entries to array
oFldDDArray(i - 1) = oFld.DropDown.ListEntries(i).Name
Next i
a = LBound(oFldDDArray)
MsgBox a 'Returns 0
MsgBox oFldDDArray(a) 'returns first item in array
z = UBound(oFldDDArray)
MsgBox z 'Returns 5. Why? Only 5 items in the array (0-4)
MsgBox oFldDDArray(z) 'Empty
MsgBox oFldDDArray(z - 1) 'Returns last item in array
End Sub