Today's Posts Follow Us On Twitter! TFL Members on Twitter  
Forum search: Advanced Search  
Navigation
Marketplace
  Members Login:
Lost password?
  Forum Statistics:
Forum Members: 24,255
Total Threads: 81,172
Total Posts: 566,860
There are 75 users currently browsing (tf).
 
  Our Partners:
 
  TalkFreelance     Design and Development     Programming     .NET and MSSQL :

My VB Homework

Thread title: My VB Homework
     
    Thread tools Search this thread Display Modes  
Prev Previous Post   Next Post Next
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
     


Thread Tools
Display Modes

  Posting Rules  
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump:
 
  Contains New Posts Forum Contains New Posts   Contains No New Posts Forum Contains No New Posts   A Closed Forum Forum is Closed