Skip to content

Instantly share code, notes, and snippets.

@jda0
Created December 12, 2013 17:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jda0/7932037 to your computer and use it in GitHub Desktop.
Save jda0/7932037 to your computer and use it in GitHub Desktop.
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