Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- '------------------------------------------------------------------------------------------
- ' Notice of My Copyright and Intellectual Property Rights
- '
- ' Any intellectual property contained within the program by Joseph L. Bolen remains the
- ' intellectual property of the Joseph L. Bolen. This means that no person may distribute,
- ' publish or provide such intellectual property to any other person or entity for any
- ' reason, commercial or otherwise, without the express written permission of Joseph L. Bolen.
- '
- ' Copyright © 2014. All rights reserved.
- ' All trademarks remain the property of their respective owners.
- '-------------------------------------------------------------------------------------------
- ' Program Name: Subroutine And Function Demo - Console App
- ' Author: Joseph L. Bolen
- ' Date Created: Aug 2014
- '
- ' Description: Demonstration of a Subroutine and a Function
- '
- ' Documentation is at:
- ' App's Visual Basic .NET code is at http://pastebin.com/ZyhdwWV5
- '
- Module Module1
- Private result As String
- Private aKey As ConsoleKeyInfo
- Sub Main()
- Do
- Console.Clear()
- Dim num1String As String = InputBox("Input first whole number", "Adding Two Numbers", "0")
- If num1String.Length = 0 Then num1String = "0"
- Dim num2String As String = InputBox("Input second whole number", "Adding Two Numbers", "0")
- If num2String.Length = 0 Then num2String = "0"
- ' Call the Subroutine
- AddTwoNumbers(num1String, num2String)
- Console.WriteLine("The sum of " & num1String.Trim & " and " & num2String.Trim & " using a Subroutine is: " & result)
- ' Use the Function
- Console.WriteLine()
- Console.WriteLine("The sum of " & num1String.Trim & " and " & num2String.Trim & " using a Function is: " & AddToNums(num1String, num2String))
- ' Hold console open until key is pressed.
- Console.WriteLine()
- Console.WriteLine("Press the ""Q"" key to end program.")
- aKey = Console.ReadKey()
- Loop While (aKey.Key <> ConsoleKey.Q)
- End Sub
- Private Sub AddTwoNumbers(ByVal pString1 As String, ByVal pString2 As String)
- Dim num1, num2 As Integer
- If Not Integer.TryParse(pString1, num1) Then
- result = vbCrLf & "Error: First value is not a whole number."
- Exit Sub
- End If
- If Not Integer.TryParse(pString2, num2) Then
- result = vbCrLf & "Error: Second value is not a whole number."
- Exit Sub
- End If
- result = (num1 + num2).ToString("n0")
- End Sub
- Private Function AddToNums(ByVal pString1 As String, ByVal pString2 As String) As String
- Dim num1, num2 As Integer
- If Not Integer.TryParse(pString1, num1) Then
- Return vbCrLf & "Error: First value is not a whole number."
- End If
- If Not Integer.TryParse(pString2, num2) Then
- Return vbCrLf & "Error: Second value is not a whole number."
- End If
- Return (num1 + num2).ToString("n0")
- End Function
- End Module
Advertisement
Add Comment
Please, Sign In to add comment