Ctype for a menu item

JuggaloBrotha

VB.NET Forum Moderator
Staff member
Joined
Jun 3, 2004
Messages
4,530
Location
Lansing, MI; USA
Programming Experience
10+
i have 4 menu items that i would like to code 1 sub for and use a select case against the sender to see which menu item was selected but i dont know what to cast the menu item as:

VB.NET:
Private Sub mnuDifficultys_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuDifficulty1.Click, mnuDifficulty2.Click, mnuDifficulty3.Click, mnuDifficulty4.Click
  Select Case CType(sender, MenuItem).Name
	Case "mnuDifficulty1": gintDifficulty = 1
	Case "mnuDifficulty2": gintDifficulty = 2
  End Select

it'd be a really easy thing to do, and i can do it this way with buttons, except i need it in a menu it would be pointless to have to code it in 4 seperate subs that i would have to maintain lol
 
You could use something like:
VB.NET:
[color=Blue]If[/color] sender [color=Blue]Is Me[/color].mnuDifficulty1 [color=Blue]Then
  [/color]gintDifficulty = 1[color=Blue]
Else If[/color] sender [color=Blue]Is Me[/color].mnuDifficulty2 [color=Blue]Then
  [/color]gintDifficulty = 2[color=Green]
'...[color=Blue]
[/color][/color][color=Blue]End If[/color]
 
lol yes i could just do that i knew it had to be something easy

though while still on the topic i guess it could still be a select case statement as well too such as:
VB.NET:
Select Case sender
  Case Is Me.mnuDifficulty1
	gintDifficulty = 1
  Case Is Me.mnuDifficulty2
 	gintDifficulty = 2
End Select

right?
 
JuggaloBrotha said:
...though while still on the topic i guess it could still be a select case statement ... right?
I would guess so. I come from a C background where the switch statement is more limited than Select Case. I've used Is with Case so infrequently that I'd forgotten you could. :)
 
Back
Top