Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Control/Reference events. 2

Status
Not open for further replies.

WhyIsIt

Programmer
Oct 9, 2003
4
GB
Hi there.

I am used to VB6, and when you double click on a control, an even sub is started, for example, double clicking on a command button brings up this:

Code:
Private Sub Command1_Click()

End Sub

Then other events can be found using a drop down list.

However, i cannot work out how to get different events in VB.NET :-( I would especially like to know how to do it for the winsock reference thingymaboper lol. Also, what is the propper way to get the reference into my code? for example, in VB6,
Code:
Dim myvar As somethingHere
is placed at the very top of the code, but in V.NET, there is loads of other stuff at the top of the page too.

Can you help?

Thanks!
 
To access a control's event procedure is pretty much the same as VB6, double click on the control and then use the drop-down list at the top-right of the window if you want to go to a different event.

If you want to declare a global variable, it needs to be declared inside your class, but outside of all methods, ie:

Code:
Public Class Form1
    Inherits System.Windows.Forms.Form

#Region " Windows Form Designer Generated Code "
  'Loads of info in here that you most probably don't need to worry about!
#End Region

'Declare you global variables here.
'No value given.
Public myGlobalVariable As Integer

'Value given.  Note, this is not a constant - you can still change the value as normal.
Public myGlobalAssignedVariable As String = "Hello"

'Then your methods.
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e as System.EventArgs) Handles Button1.Click

'code

End Sub

End Class


There's a thin line between genius, and insanity!
 
Thanks for the help - however, i have 1 more question.

How can i reach the events from the MSWinsock reference?

To add it, i have added the reference:

Project --> Add reference --> COM --> MSWinsock Control 6

Then have added a global variable:
Public Winsock1 As MSWinsockLib.Winsock()

How can i get the different events for this? what have i done wrong/what else needs doing?

Thanks!!
 
Try changing "Public Winsock1 As MSWinsockLib.Winsock()" with "Public Winsock1 As New MSWinsockLib.Winsock()".

You should be able to access the events as normal now, ie. Winsock1.SomeEvent.

Hope it works.

T0AD

There's a thin line between genius, and insanity!
 
Thanks BUT - adding 'New' is the same as leaving it out.

I am able to get the winsock1.Something, but i need to be able to get the event procedures.

For example;
Code:
Public Winsock1 As New MSWinsockLib.Winsock
'
'
Private Sub Winsock1.DataArival(some stuff here)
Winsock1.GetData.........
End Sub

At the moment, i cannot get to the different events of the reference, only the controls. (i can use the winsock control - but i dont want an extra file in my setup :) lol)

Is this even possible? lol

Thanks very much for your help!!!!

 
Ah okay. Try using the WithEvents keyword, something like:

Code:
Public WithEvents myButton As New Button

Private Sub myEvent(ByVal sender As Object, e As EventArgs) Handles myButton.Click
    'Whatever you want here.
End Sub

Note the Handles myButton.Click, your method can be named whatever you like, ie. myEvent - but the Handles part tells it what event to handle.

Obviously change the Button to the Winsock reference that you're using. You'll need to make sure that the arguments in the event procedure are correct, or you'll get an error. If you have Option Strict On this should help (I always use it)

Hope it works ok now!

T0AD

There's a thin line between genius, and insanity!
 
THANK YOU!

HEHE - it works :)


I have one last problem - then i will be ready to code the rest of my program for world domination *** oops, i mean errr, yeah... :p


I havent written any code yet, BUT, the
Code:
    Private Sub Winsock1_Connect() Handles Winsock1.Connect

    End Sub
The last "Connect" (Handles Winsock1.Connect) is underlined with the squigly blue line thing (lol - you can tell im good at all this) and it says
'Connect' is ambiguous accross the inherited interfaces
'MSWinsockLib.IMSWinsockControl' and
'MSWinsockLib.DMSWinsockControlEvents_Event'
(Thats what the mouse hover tool-tip text thing says.

Any ideas??

Thanks!!
 
Hmm, sorry can't help. Try looking up "ambiguous" in the Help Index.

Hope you don't hold this against me when you're ruling the world!! (your name isn't Saddam by any chance is it?!!)

Maybe someone else can help??

T0AD

There's a thin line between genius, and insanity!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top