Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Class Form1
- Dim myobj As Object, answer As Integer
- Sub start() Handles Button1.Click 'this sub executes when the button is clicked.
- myobj = New calcu
- myobj.num1 = 4
- myobj.num2 = 3
- 'Should give us 7
- answer = myobj.add()
- If Not answer Then
- MsgBox("Incorrect data type! " & answer)
- 'Exit sub to stop the execution of the normal message box
- Exit Sub
- End If
- MsgBox(answer)
- End Sub
- End Class
- Class calcu
- Public num1 As Integer
- Public num2 As Integer
- Public Function add() As Integer
- If Not IsNumeric(Me.num1) Or Not IsNumeric(Me.num2) Then ' The user entered an invalid char. Return false
- Return False
- End If
- Return Me.num1 + Me.num1 'add the two passed parameters and return the answer
- End Function
- End Class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement