Really dumb question about As 
Author Message
 Really dumb question about As

Hi. Despite speaking no VB, I was asked last week to produce a VB.NET
example of the use of an ActiveX control that a friend of mine built.
This has been a surprisingly pleasant experience -- I was expecting
the impossible part to be embedding the ActiveX control, whilst all I
had to do was drag-and-drop -- until I came to a Menu Problem.

I've got a menu zoomMenu with entries zoom50, zoom100, zoom150,
zoom200. At the moment, I have handlers looking like

 ... handles zoom50.Click
  zoom50.Checked=true;
  zoom100.Checked=false;
  zoom150.Checked=false;
  zoom200.Checked=false;

In C#, I could just do

foreach Menuitem t in zoomMenu.MenuItems {t.Checked = false;}
((MenuItem)sender).Checked = true;

I thought the second line translated into VB as

(sender As MenuItem).Checked = true;

but this gave weird syntax errors when compiled.

I couldn't find a suitable example in the documentation -- any query I
tried gave back five hundred answers, and when I looked through them
most of them seemed irrelevant. I realise this is a fundamental VB
question; I apologise for not knowing the language and hoping that I
could pick it up as I went along.



Fri, 13 May 2005 19:43:28 GMT  
 Really dumb question about As
Hi Tom,

Quote:
> foreach Menuitem t in zoomMenu.MenuItems {t.Checked = false;}
> ((MenuItem)sender).Checked = true;

Dim t as MenuItem ' note: in 1.1 you can inline this in the for each
For each t in zoomMenu.MenuItems
    t.Checked = false
Next
CType(sender, MenuItem).Checked = true


Quote:
> Hi. Despite speaking no VB, I was asked last week to produce a VB.NET
> example of the use of an ActiveX control that a friend of mine built.
> This has been a surprisingly pleasant experience -- I was expecting
> the impossible part to be embedding the ActiveX control, whilst all I
> had to do was drag-and-drop -- until I came to a Menu Problem.

> I've got a menu zoomMenu with entries zoom50, zoom100, zoom150,
> zoom200. At the moment, I have handlers looking like

>  ... handles zoom50.Click
>   zoom50.Checked=true;
>   zoom100.Checked=false;
>   zoom150.Checked=false;
>   zoom200.Checked=false;

> In C#, I could just do

> foreach Menuitem t in zoomMenu.MenuItems {t.Checked = false;}
> ((MenuItem)sender).Checked = true;

> I thought the second line translated into VB as

> (sender As MenuItem).Checked = true;

> but this gave weird syntax errors when compiled.

> I couldn't find a suitable example in the documentation -- any query I
> tried gave back five hundred answers, and when I looked through them
> most of them seemed irrelevant. I realise this is a fundamental VB
> question; I apologise for not knowing the language and hoping that I
> could pick it up as I went along.



Fri, 13 May 2005 19:53:13 GMT  
 Really dumb question about As
Us the CType command for casting.
CType(sender,MenuItem).Checked = True

Cheers,
  Jason


Quote:
> Hi. Despite speaking no VB, I was asked last week to produce a VB.NET
> example of the use of an ActiveX control that a friend of mine built.
> This has been a surprisingly pleasant experience -- I was expecting
> the impossible part to be embedding the ActiveX control, whilst all I
> had to do was drag-and-drop -- until I came to a Menu Problem.

> I've got a menu zoomMenu with entries zoom50, zoom100, zoom150,
> zoom200. At the moment, I have handlers looking like

>  ... handles zoom50.Click
>   zoom50.Checked=true;
>   zoom100.Checked=false;
>   zoom150.Checked=false;
>   zoom200.Checked=false;

> In C#, I could just do

> foreach Menuitem t in zoomMenu.MenuItems {t.Checked = false;}
> ((MenuItem)sender).Checked = true;

> I thought the second line translated into VB as

> (sender As MenuItem).Checked = true;

> but this gave weird syntax errors when compiled.

> I couldn't find a suitable example in the documentation -- any query I
> tried gave back five hundred answers, and when I looked through them
> most of them seemed irrelevant. I realise this is a fundamental VB
> question; I apologise for not knowing the language and hoping that I
> could pick it up as I went along.



Fri, 13 May 2005 19:58:43 GMT  
 Really dumb question about As

Quote:

> Hi Tom,

> > foreach Menuitem t in zoomMenu.MenuItems {t.Checked = false;}
> > ((MenuItem)sender).Checked = true;

> Dim t as MenuItem ' note: in 1.1 you can inline this in the for each
> For each t in zoomMenu.MenuItems
>     t.Checked = false
> Next
> CType(sender, MenuItem).Checked = true

Thanks very much! That's tidied up the program immensely.

I can't help thinking there ought to be some way of telling a menu
that it should have at most one of [some group of entries] ticked; I'm
sure there was one in MFC. But RadioCheck only changes the ticks into
blobs, rather than requiring that there be precisely one blob, and I
can't see anything which looks like a property I could group on.



Sat, 14 May 2005 18:02:13 GMT  
 Really dumb question about As
Hi Tom,

Well it depends on the circumstance , but if you are coding all of it, you could
create a store or set of stores.  For example, let's say the condition was only
one checked menu item for a group then you could store a variable for that group.
In your example code, that could be done as :

'code in the click event :
CheckMenuExclusive(Ctype(sender,MenuItem))

Then have the following code:

Private m_MenuGroups as New HashTable()

Public Function CheckMenuExclusive(ByVal menu as MenuItem)
    Dim mi as MenuItem
    mi = m_MenuGroups(menu.Parent)
    If not mi Is Nothing Then
        mi.Checked = False
    End If
    menu.Checked = True
    m_MenuGroups(menu.Parent) = menu
End Function

Alternatively, you could use string keys for the groups instead of using the
menu.Parent.  That would probably be preferable as it would allow multipel groups
on the one menu.



Quote:
> > Hi Tom,

> > > foreach Menuitem t in zoomMenu.MenuItems {t.Checked = false;}
> > > ((MenuItem)sender).Checked = true;

> > Dim t as MenuItem ' note: in 1.1 you can inline this in the for each
> > For each t in zoomMenu.MenuItems
> >     t.Checked = false
> > Next
> > CType(sender, MenuItem).Checked = true

> Thanks very much! That's tidied up the program immensely.

> I can't help thinking there ought to be some way of telling a menu
> that it should have at most one of [some group of entries] ticked; I'm
> sure there was one in MFC. But RadioCheck only changes the ticks into
> blobs, rather than requiring that there be precisely one blob, and I
> can't see anything which looks like a property I could group on.



Sat, 14 May 2005 18:22:04 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. This is a really really dumb question.

2. really dumb question

3. Really dumb question

4. A really dumb question... OS Detection

5. Really dumb question

6. Really dumb question: How do I call one .EXE from another, passing parms into the constructor?

7. Really dumb textbox newbie question..

8. Newbie: dumb question, very dumb....

9. this is going to sound really dumb...

10. Really dumb : creating a hyperlink ?

11. Really dumb : creating a hyperlink ?

12. Really really stuck on this one. (QBasic Question)

 

 
Powered by phpBB® Forum Software