I "see" 4 textboxes:
d1
- input value,
q1
- input value,
un1
- input value,
amt1
- result.
To solve your problem, just add new button and move the body of
q1_TextChanged()
procedure into
Button1_Click()
procedure.
To clear textboxes, copy code below and paste it before
Me.Refresh()
command:
d1.text = ""
q1.text = ""
un1.text = ""
Now, your textboxes are clear.
****************[EDIT]Second solution - step by step with custom Class and Interface[EDIT]****************
1) Create new (windows application) project
2) Add 4 lables and 4 texboxes and change them names as follows: TxtVal1, TxtVal2, TxtVal3, TxtVal4
3) Add 1 button (Name: BtnCalc)
4) Add new
Interface[
^] (menu Project->Add new item->Interface) and save it as "ITestCalc.vb". We need it to correspond with between class and form.
5) Copy and paste code below:
Public Interface ITestCalc
Function Calc() As Integer
Function Calc(ByVal _d1 As Integer, ByVal _q1 As Integer, ByVal _un1 As Integer) As Integer
Property D1() As Integer
Property Q1() As Integer
Property Un1() As Integer
End Interface
6) Add new
Class[
^] to the project (Menu Project->Add new item->Class) and save it as "TestCalc.vb"
7) Copy code below and paste it into your class:
Public Class TestCalc
Implements ITestCalc
Private d1 As Integer = 0
Private q1 As Integer = 0
Private un1 As Integer = 0
Public Sub New()
End Sub
Public Sub New(ByVal _d1 As Integer, ByVal _q1 As Integer, ByVal _un1 As Integer)
d1 = _d1
q1 = _q1
un1 = _un1
End Sub
Public Function Calc() As Integer Implements ITestCalc.Calc
Dim retVal As Integer = 0
retVal = d1 * q1 * (un1 / 30)
Return retVal
End Function
Function Calc(ByVal _d1 As Integer, ByVal _q1 As Integer, ByVal _un1 As Integer) As Integer Implements ITestCalc.Calc
d1 = _d1
q1 = _q1
un1 = _un1
Return Calc()
End Function
Public Property D11() As Integer Implements ITestCalc.D1
Get
Return d1
End Get
Set(ByVal value As Integer)
d1 = value
End Set
End Property
Public Property Q11() As Integer Implements ITestCalc.Q1
Get
Return q1
End Get
Set(ByVal value As Integer)
q1 = value
End Set
End Property
Public Property Un11() As Integer Implements ITestCalc.Un1
Get
Return un1
End Get
Set(ByVal value As Integer)
un1 = value
End Set
End Property
Protected Overrides Sub Finalize()
MyBase.Finalize()
End Sub
End Class
8) In the form (class):
Public Class Form1
Private oCalc As ITestCalc = New TestCalc()
Private Sub BtnCalc_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnCalc.Click
Try
oCalc.D1 = Int(Me.TxtVal1.Text)
oCalc.Q1 = Int(Me.TxtVal2.Text)
oCalc.Un1 = Int(Me.TxtVal3.Text)
Me.TxtResult.Text = oCalc.Calc().ToString
Catch ex As InvalidCastException
MsgBox(ex.Message & vbCr & vbCr & _
"Enter correct values!", MsgBoxStyle.Exclamation, "Error!")
Catch ex As Exception
MsgBox(ex.Message, MsgBoxStyle.Exclamation, "Error!")
End Try
End Sub
Protected Overrides Sub Finalize()
oCalc = Nothing
MyBase.Finalize()
End Sub
End Class
If my answer was helpful, please rate it.