Thread: My VB Homework
View Single Post
02-09-2007, 12:13 AM
#1
Jack Morrison is offline Jack Morrison
Jack Morrison's Avatar
Status: Member
Join date: Dec 2005
Location: Ontario, Canada
Expertise:
Software:
 
Posts: 264
iTrader: 0 / 0%
 

Jack Morrison is on a distinguished road

Send a message via AIM to Jack Morrison Send a message via MSN to Jack Morrison Send a message via Yahoo to Jack Morrison Send a message via Skype™ to Jack Morrison

  Old  My VB Homework

VB is new to me, dont laugh.

Part of the assignment is to make a simple calculator macro in Microsoft Excel. I've tested it and it seems to work pretty well, just wanted to post the code and see if anyone sees any major errors or improvements I can make.

Code:
Option Explicit
'Written by Jack Morrison

Sub mytoycalculator()
Dim Num1 As Integer
Dim Num2 As Integer
Dim Operator As String * 1
Dim Answer As Integer
Dim Success As Boolean

Num1 = InputBox("Enter the First Value")
Num2 = InputBox("Enter the Second Value")
Operator = InputBox("Enter the sign of the operation")

If Operator = "+" Then
Answer = (Num1 + Num2)
Success = True
ElseIf Operator = "-" Then
Answer = (Num1 - Num2)
Success = True
ElseIf Operator = "*" Then
Answer = (Num1 * Num2)
Success = True
ElseIf Operator = "^" Then
Answer = (Num1 ^ Num2)
Success = True
ElseIf Operator = "/" And (Num2 <> 0) Then
Answer = (Num1 / Num2)
Success = True
Else
Success = False
End If

If Success = True Then
MsgBox ("The Operation was successful, The Answer is " & Answer)
 
ElseIf Success = False Then
MsgBox ("The Operation Failed")
End If
End Sub
Thanks,

Axiom

Reply With Quote