Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

how to find size of menu control array

Status
Not open for further replies.

redss

Programmer
Joined
Oct 20, 2002
Messages
195
I have a dynamically loaded menu object - how can I tell if a menu item is loaded?

I.e. there might be 3 or 10 menu items, but I can't say
Code:
  if mnuOption(3) = nothing then...
and also I can't seem to say get the number of menu items loaded (via "load mnuOption(i)") with the UBOUND command either...

Any ideas?
 
With VB6, accessing an out-ouf-bound item from an array or collection will raise an error. So, here's a tip:
Code:
Dim selMenu As Integer
selMenu = 3
If mnuOption.Ubound >= selMenu Then
    'to do: mnuOption exists
End If
If there are 10 menu items, [tt]Ubound()[/tt] will return 9. To check if the menu you selected exists, selMenu must be less or equal to upper bound of array/collection.

Hope this helps. [peace]
 
I was supposed to preview my post first. I just want to add that the tip is applicable if menu items are created and destroyed LIFO(last-in first-out). Then again, even if selected menu index is within bounds but does not really exists, you need to do error trapping.
Code:
Dim selMenu As Integer
selMenu = 3
If mnuOption.Ubound >= selMenu Then
    'On Error Goto YourErrHandler
    'to do: mnuOption exists
End If
[peace]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top