Jump to content
Xtreme .Net Talk

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


Recommended Posts

Posted

Hi. Can somebody tell me what's wrong with the following line:

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.

Posted

But if I take the RaiseEvent away and just call it directly, ie.

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?

  • *Experts*
Posted (edited)
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. Edited by mutant
Posted

sorry... I'm pretty new to VB... what do you mean by "class" the sub?

 

Are you recommending something like this:

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.

  • *Experts*
Posted

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:

DirectCast(FMsg, frmMsg).SubThatHandlesTheEvent(arguments)

You would have to make that event handler sub public.

Posted

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?

  • *Experts*
Posted
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? :)
Posted

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.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...