Below are two examples of handlers for the ADD button.
(The first example is not modularized; the second example is)
Private Sub btnAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) _ Handles btnAdd.Click '''' Sum the two numbers. '''' DECLARATIONS: Dim first As Double Dim second As Double Dim answer As Double '''' INPUT '''' first = Val(Me.txtFirst.Text) ' Convert string to # second = Val(Me.txtSecond.Text) '''' PROCESSING '''' answer = first + second ' Add numbers '''' OUTPUT '''' Dim s As String Dim t As String s = "The sum is " t = Format(answer) ' Convert # to string Me.lstAnswers.Items.Add(s + t) End Sub
The second code example is fully "modularized" to simplify its "re-use" for other buttons.
Private Sub btnAdd_Click( ..., ... ) Handles btnAdd.Click '''' Input two numbers, process them, produce labelled output. Dim first as Integer = getFirst() '''' INPUT '''' Dim second as Integer = getSecond() Dim s as String '''' PROCESSING '''' answer = calcAdd( first, second ) s= "The sum is " '****** FOR RE-USE, CHANGE THE ABOVE TWO LINES '****** (AND WRITE A NEW calc FUNCTION). call saywhat ( s, answer ) '''' OUTPUT '''' End Sub Function calcaAdd( a as Integer, b as Integer) as Integer '''' Add the two numbers. Dim result as Integer result= a + b return result End Function '======= INPUT METHODS ========' Function getFirst() as Integer '''' Get the first input; convert to integer value. '''' return Val(Me.txtFirst.Text) ' Convert string to # End Function Function getSecond() as Integer '''' Get the 2nd input; convert to integer value. '''' return Val(Me.txtSecond.Text) ' Convert string to # End Function '======= OUTPUT METHODS ========' Sub getFirst( msg as string, v as integer ) '''' Display a message followed by a value. Me.lstAnswers.Items.Add( msg + Format(v) ) End Sub