[Tutor] OOP programming using VB
alan.gauld at blueyonder.co.uk
Sat Jan 24 13:07:26 EST 2004
> I have never done OO programming using VB . Anyway I have used OOP
> concepts with C++. I have no clear idea of how to use OOP concepts
> with VB forms and all,
Its pretty similar to C++. A form is an object in VB and it has
methods etc which you can call. When you add components you
define an action or event handler which is effectively a
method of the form object.
You can also define your own classes using a blank code page
like this rather trivial example copied from the paper version
of my book...
Public Property Let Text(S)
theText = S
Pubic Sub Print()
If theText = "" Then
WSCript.echo "No Message"
For n = 1 to 3
set Msg = new Message
Msg.Text = "Hello world"
The equivalent code in Python (Since this is a Python mailing
list) is as follows:
def __init__(self, text = ""):
self.theText = text
if self.theText == "":
print "No Message"
for n in range(3):
msg = Message("Hello world")
I'll let you figure out the equivalent C++ (Or you can buy the book!
NOTE the above example is actually in VBScript. There might be
some minor syntax diffrences in VB proper but its very similar.
Author of the Learn to Program web tutor
More information about the Tutor