Beginning ActiveX - Part 1
Method is just a collective name for the subs and functions of your control. These are just the same as any other functions that you have written in your VB career. You can pass any number of parameters and return a value if you want. In the look method of our body, we want to pass the direction that the eye is looking. This method might be:
Public Sub Look(Direction As Integer) Select Case Direction Case 0 '=Left 'look left Case 1 '=Right 'look right Case 2 '=Up 'look up Case 3 '=Down 'look down End Select End Sub
For all the fancy names, this is all that it is. To return a value, we will use our read method as an example, you must declare it as a function instead of a sub:
Public Function Read() As String 'Do reading stuff Read = "Hello from VB-World.net" End Function
Isn't all this method stuff easy? If you really can't get the idea sorted in your head, think of it like this: your control is like a machine. You put information in the top, turn the handle, your method, some lights will flash and the machine will start doing things, eventually giving you a final value out the bottom. But wait...what if your machine wants to tell you something? It's a great event when that happens...
Page 3 of 7
This article was originally published on November 20, 2002