Created
December 12, 2013 17:36
-
-
Save jda0/7932037 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Public Class Form1 | |
' Form Controls: Label Label1, TextBox TextBox1, Button Button1, Button Button2, Label Label2 | |
Private output As Integer | |
Private Sub CalculateProc(n As Integer) | |
output = n * 2 | |
End Sub | |
Private Function CalculateFn(n As Integer) As Integer | |
Return n * 3 | |
End Function | |
Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click | |
Try | |
CalculateProc(TextBox1.Text) ' This calls the procedure CalculateProc using TextBox1.Text as a parameter | |
Label2.Text = "Output: " & output ' This assigns output to Label2.Text | |
Catch ex As InvalidCastException | |
Label2.Text = "Error: Invalid input." | |
End Try | |
End Sub | |
Private Sub Button2_Click(sender As System.Object, e As System.EventArgs) Handles Button2.Click | |
Try | |
Label2.Text = "Output: " & CalculateFn(TextBox1.Text) | |
Catch ex As Exception | |
Label2.Text = "Error: Invalid input." | |
End Try | |
End Sub | |
End Class |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment