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

JDogg

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

VB doesnt like CTypes presence, but I cant 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 by a moderator:
sorry... Im 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 youre suggesting; again theres parts of VB I completely dont 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:
Code:
DirectCast(FMsg, frmMsg).SubThatHandlesTheEvent(arguments)
You would have to make that event handler sub public.
 
Im starting to see what you mean... I had to read up on exactly what "events" and "handlers" were... :)

The thing I dont 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 dont do anything, ie. they dont 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 its 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? :)
 
Heres 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.

Im 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