dynamic menu confusion

Hi. Hope all is well with you folks.
I found an example code in the docs for creating a font menu item and populating it with all the fonts on your system. Trouble is, when I run it as given, it’s loaded with debugger errors. I tried to deal with the errors myself, but only succeeded in confusing myself. Can anybody help me sort this out?
Here’s what it says in the docs:

[code]Dynamic Menus
Sometimes you may need to create a menu dynamically. Examples of this include a menu that shows recently opened files, a menu that shows the names of the currently open windows or a menu that shows the name of available fonts.

To do this you create a MenuItem subclass and use the Append and Insert methods of the MenuItem class to add instances of your subclass to the menu bar.

Here is an example that adds a Font menu. Create a new MenuItem subclass (called FontMenuItem). In its Action event add this code:

MsgBox("Selected Font: " + Self.Text)
Reminder: To create a MenuItem subclass, create a new class and set its Super to MenuItem.
Now you can use this subclass to create a font menu. In the Open event of the default window, add this code:

mFontMenu = New MenuItem(“Font”)
MenuBar1.Append(mFontMenu)
Dim fCount As Integer = FontCount
Dim fMenu As FontMenuItem
For i As Integer = 0 To fCount-1
fMenu = New FontMenuItem(Font(i))
mFontMenu.Append(fMenu)
Next
This code creates a new top-level menu called “Font” and adds to it a menu item for each font that is installed on your system. When you run the application and click the Font menu, you will see a list of all the fonts. Click on a font and a dialog appears telling you the name of the one you clicked.[/code]

Just quoting the docs does us no good as we all have access to them. Show us the code you are trying. Did you create a menu item subclass as described? What errors are you seeing. Show the code and where the errors occur.

The code I’m using is identical what the docs provide as an example, which is already shown above. Yes, I did create a FontMenuItem class and set its super to MenuItem. I tried changing the default MainMenuBar name to MenuBar1 to see if that helps. Same errors occur.

Errors:
Window1.Open, line 1
This item does not exist
mFontMenu = New MenuItem(“Font”)

(mFontMenu is highlighted)

Window1.Open, line 2
This item does not exist
MenuBar1.Append(mFontMenu)

(MenuBar1 is highlighted)

Window1.Open, line 4
Can’t find a type with this name
Dim fMenu As FontMenuItem

(FontMenuItem is highlighted)

Window1.Open, line 6
Can’t find a type with this name
fMenu = New FontMenuItem(Font(i))

(FontMenuItem is highlighted)

Window1.Open, line 7
This item does not exist
mFontMenu.Append(fMenu)

(mFontMenu is highlighted)

Bill

Put this code into open event of Window

[code]

Dim myFonts As New FontMenuItem(“Font”)
MainMenubar.Append(myFonts)

Dim fCount As Integer = FontCount
Dim fMenu As FontMenuItem
For i As Integer = 0 To fCount-1
fMenu = New FontMenuItem(Font(i))
myFonts.Append(fMenu)
Next[/code]

[quote=389864:@brian franco]Dim myFonts As New FontMenuItem(“Font”)
MainMenubar.Append(myFonts)

Dim fCount As Integer = FontCount
Dim fMenu As FontMenuItem
For i As Integer = 0 To fCount-1
fMenu = New FontMenuItem(Font(i))
myFonts.Append(fMenu)
Next[/quote]
Dude, you’re awesome. Thank you so much!

Bill,

glad you got it working

:smiley:

[quote=389868:@brian franco]Bill,

glad you got it working

:D[/quote]
Well, actually, YOU got it working. :wink: