I have been working on this literally all day. I made strmathoperation a string because that's what my directions said, "declare a string variable called MathOperation to hold the math operation to perform." And I have to use the select case/case else structure.
Option Explicit
Dim intanswer As Integer
Dim intnum1 As Integer
Dim intnum2 As Integer
Dim strmathoperation As String
Public Sub Main()
intnum1 = Val(InputBox("Please enter the first operand", "First operand"))
intnum2 = Val(InputBox("Please enter the second operand", "Second operand"))
strmathoperation = Val(InputBox("Enter +,-,*,or / for math operation", "Math operation"))
Call operation(intnum1, intnum2, strmathoperation)
SendResult
End Sub
Private Function operation(intnum1 As Integer, intnum2 As Integer, strmathoperation As String)
Select Case strmathoperation
Case "+"
operation = intnum1 + intnum2
Case "-"
operation = intnum1 - intnum2
Case "*"
operation = intnum1 * intnum2
Case "/"
operation = intnum1 / intnum2
Case Else
operation = 0
End Select
End Function
Private Sub SendResult()
MsgBox "The answer is: " & operation(intnum1, intnum2, strmathoperation)
End Sub
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Call Main
End Sub
Again any help is much appreciated.
Bookmarks