# I want to clean up this console app calculator (VB.net)

Getting started in VB.net I've written this console calculator based heavily off Nicholas Dingle youtube channel (in case it looks familiar). What I want to do is have a separate sub called Operation(parameter) and take the if statements out of CollectNumbers() since it doesn't make sense to have them in that sub. To make this happen I think what i'll end up needing to do is use Enum for the different operations, but don't know how to implement it. I think also the calling of CollectNumbers() will have to be reworked as well. I'm not looking for anyone to write it out, but a nudge in the right direction or tips would be very helpful.

Imports System.Runtime.Remoting.Services

Module Module1

Sub Main()

End Sub

'Enum operations

'    Subtract = 2
'    Multiply = 3
'    Divide = 4

'End Enum

Dim selection As String

Console.Clear()

Console.WriteLine("Say Hello To My Little Calculator!")
Console.WriteLine() 'print blank line
Console.WriteLine() 'print blank line
Console.WriteLine("(S) to Subtract")
Console.WriteLine("(M) to Multiply")
Console.WriteLine("(D) to Divide")
Console.WriteLine("(Q) to Quit")

If selection.ToUpper = "Q" Then
Console.WriteLine("Exiting...")
Environment.Exit(0)
ElseIf selection.ToUpper = "A" Then
ElseIf selection.ToUpper() = "S" Then
CollectNumbers("subtract")
ElseIf selection.ToUpper() = "M" Then
CollectNumbers("multiply")
ElseIf selection.ToUpper() = "D" Then
CollectNumbers("divide")
Else
Console.WriteLine("Please choose a valid option from the list...")
End If

End Sub

Sub CollectNumbers(operation As String)

Dim num1 As Integer
Dim num2 As Integer

ElseIf operation = "subtract" Then
Console.WriteLine(Subtract(num1, num2))
ElseIf operation = "divide" Then
Console.WriteLine(Divide(num1, num2))
ElseIf operation = "multiply" Then
Console.WriteLine(Multiply(num1, num2))
End If

End Sub

Function Add(a As Integer, b As Integer) As Double

Return a + b

End Function

Function Subtract(a As Integer, b As Integer) As Double

Return a - b

End Function

Function Multiply(a As Integer, b As Integer) As Double

Return a * b

End Function

Function Divide(a As Integer, b As Integer) As Double

Return a / b

End Function

End Module

• Thanks for the ping, I've re-read your post and glanced at the code, and you're right obviously; please accept my apologies. Consider rewording the "I think what i'll end up needing to do is use Enum for the different operations, but don't know how to implement it" part: it's what made me make the call, and likely what made others do the same. Aug 31 '20 at 18:32
• @MathieuGuindon Understood. Still learning the etiquette on these exchange sites. Aug 31 '20 at 18:35
• No problem! How to get the best value out of CR is without a doubt one of the best resources available to help with that. Aug 31 '20 at 18:40