Modify a text file: $/0a01.vb
$/0a01.vb
Public Class Form1 '******** OUTPUT METHODS ******* Sub say(ByVal s As String) '**** Output a string to the listbox. Me.output.Items.Add(s) 'Display the string s in listbox. End Sub Sub saywhat(ByVal s As String, ByVal r As Double) '**** Output a string and a value to the listbox. Me.output.Items.Add(s & " " & Format(r)) 'Display string s & r in listbox. End Sub Private Sub btnDiv_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDiv.Click '****** Divide, but check for div by zero. Output result (or err msg). Dim a, b As Double ' First and second inputs (from txtFirst, txtSecond) Dim result As Double ' Result of operation. Dim msg As String 'The output string will be composed here. Dim what As String = "quotient" 'Result type. '1. INPUT: Get a, b a = CDbl(Me.txtFirst.Text) b = CDbl(Me.txtSecond.Text) '2. PROCESS: Compute the quotient, but first check for /0 If (b <> 0) Then result = a / b '-- msg = "The quotient is " & Format(result) msg = "The " & what & " is " & Format(result) Else msg = "!!!! Denominator cannot be zero!" End If '3. OUTPUT: Show the answer. say(msg) End Sub Private Sub btnMul_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnMul.Click '****** Multiply 2 #s. Output result (or err msg). Dim a, b As Double ' First and second inputs (from txtFirst, txtSecond) Dim result As Double ' Result of operation. Dim msg As String Dim what As String = "product" '0. INIT: msg = "The " & what & " is " '1. INPUT: Get a, b a = CDbl(Me.txtFirst.Text) b = CDbl(Me.txtSecond.Text) '2. PROCESS: Compute the quotient, but first check for /0 result = a * b '3. OUTPUT: Show the answer. saywhat(msg, result) End Sub End Class