"RaiseEvent CType..." not working in VB .NET

JDogg

Newcomer
Joined
Aug 26, 2003
Messages
12
Hi. Can somebody tell me what's wrong with the following line:
Code:
RaiseEvent CType(FMsg, frmMsg).btn(2).Move

VB doesn't like CType's presence, but I can't refer to btn(2) without casting FMsg.
I tried putting brackets around all of CType(FMsg, frmMsg).btn(2).Move but VB underlined the opening bracket and said "identifier expected" in the task list.

Thanks in advance.
 
But if I take the RaiseEvent away and just call it directly, ie.
Code:
CType(FMsg, frmMsg).btn(2).Move(ButtonLeft + 2820, ButtonTop)
it says in the task list that Move() cannot be called directly, and I should use RaiseEvent.

What should I do?
 
If you want to execute the code that you have in the handler of Move event then simply call the sub that is the handler, not the event.
 
Last edited:
sorry... I'm pretty new to VB... what do you mean by "class" the sub?

Are you recommending something like this:
Code:
RaiseEvent CType(FMsg.btn(2), Control).Move(ButtonLeft + 2820, ButtonTop)
That may be the farthest thing from what you're suggesting; again there's parts of VB I completely don't understand.
 
Im very sorry, i was thinking of a class when writing this and wrote class instead of call :rolleyes: . (I edited my post)
What I mean is that:
Visual Basic:
DirectCast(FMsg, frmMsg).SubThatHandlesTheEvent(arguments)
You would have to make that event handler sub public.
 
I'm starting to see what you mean... I had to read up on exactly what "events" and "handlers" were... :)

The thing I don't get now is that the "btn" that I refer to is just an array of buttons placed on frmMsg... so frmMsg just inherits the handlers for the buttons' move events... but these handlers are empty, they don't do anything, ie. they don't appear in the code for frmMsg, only in the drop down menu of methods at the top of the screen, and when I select one it's just an empty sub...

u know what I mean?
 
f im understanding you correctly you are trying to raise an event that does nothing, is that right? Then if you have no code for the event what is the prupose of it? :)
 
Here's my situation: I need to move a button at runtime. I originally wrote the code in VB 6.0, and in order to move the button I just triggered its Move event. Now I need to be able to do that in VB .NET.

I'm just learning about events, so I got confused earlier when you were talking about handlers. I want to actually trigger the event, not just respond to it.
 
Back
Top