stu nicholls dot com | menu - Professional dropdown #3



Constructors and Destructors
How to add a constructor to a class? Public Class Form1
Dim o1 As New dataclass()
Dim o2 As New dataclass(7)
Public Class dataclass
Private value As Integer
Public Sub New()
End Sub
Public Sub New(ByVal newValue As Integer)
value = newValue
End Sub
Public Function getdata() As Integer
Return value
End Function
End Class
Private Sub Button1_Click(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles Button1.Click
MsgBox(o1.getdata())
End Sub
Private Sub Button2_Click(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles Button2.Click
MsgBox(o2.getdata())
End Sub
End Class
Example::
Public Class Form1 Dim object1 As New class1()
Public Class class1
Protected Overrides Sub finalize()
Beep()
End Sub
Public Sub disp()
MessageBox.Show("Hello")
End Sub
End Class
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load object1.disp()
End Sub
End Class


Note: When the Form is closed the finalize( )method is called automatically.

Scope and Access Levels

<< Previous   Next>>


comments powered by Disqus
Footer1