VB Script - Simple Calculator Using Procedure Call
Steps to Run:
1] Open Notepad.exe or Notepad++.exe
2] Copy below VB script source code into notepad
3] Save File as "Calculate.vbs"
4] Run file and enter values
'Simple Calculator which take input of two values and pass operator sign (like +, -, *, /)
' Variable Declaration
Dim val1,val2,optval,results
' Get Inputbox values into declared variable
val1 = CInt(InputBox("Enter First Number Here: ","Title: Enter First Value"))
val2 = CInt(InputBox("Enter Second Number Here: ","Title: Enter Second Value"))
optval = InputBox("Enter Operator Value e.g. + , * , / , - : ","Title: Enter Operator Value")
' Call to Procedure name <MathCalc>, Pass option value to procedure
MathCalc(optval)
' Private procedure call starts
Private Sub MathCalc(optval)
'Use select case option to select the operator values
Select Case optval
Case "+"
results = (val1) + (val2)
Case "-"
results = (val1) - (val2)
Case "/"
results = (val1) / (val2)
Case "*"
results = (val1) * (val2)
End Select
End Sub
' Private procedure call End
' Print values for information using message box
MsgBox ("Your Results is : " & val1 & optval & val2 & " = " & results)
Short Summary(Learned so far):
1) An Input box,
An Input box is a way to respond to a question.
It could be something like entering a values, password or choosing between multiple options, as in the case entered two number and operator values.
2) A Message box,
A Message box is a way to display a message and allow you to answer Yes, No, Cancel, Retry or Ignore.
3) Select Case Statements,
Select Case Statements tells the code what to do based upon the users input.
3) Sub Procedure Call,
Procedure call method used to simplified the process call and re-usability .
Note*: Please Enter few remarks below, if code is helpful for you.
Thanks.!
1] Open Notepad.exe or Notepad++.exe
2] Copy below VB script source code into notepad
3] Save File as "Calculate.vbs"
4] Run file and enter values
'Simple Calculator which take input of two values and pass operator sign (like +, -, *, /)
' Variable Declaration
Dim val1,val2,optval,results
' Get Inputbox values into declared variable
val1 = CInt(InputBox("Enter First Number Here: ","Title: Enter First Value"))
val2 = CInt(InputBox("Enter Second Number Here: ","Title: Enter Second Value"))
optval = InputBox("Enter Operator Value e.g. + , * , / , - : ","Title: Enter Operator Value")
' Call to Procedure name <MathCalc>, Pass option value to procedure
MathCalc(optval)
' Private procedure call starts
Private Sub MathCalc(optval)
'Use select case option to select the operator values
Select Case optval
Case "+"
results = (val1) + (val2)
Case "-"
results = (val1) - (val2)
Case "/"
results = (val1) / (val2)
Case "*"
results = (val1) * (val2)
End Select
End Sub
' Private procedure call End
' Print values for information using message box
MsgBox ("Your Results is : " & val1 & optval & val2 & " = " & results)
Short Summary(Learned so far):
1) An Input box,
An Input box is a way to respond to a question.
It could be something like entering a values, password or choosing between multiple options, as in the case entered two number and operator values.
2) A Message box,
A Message box is a way to display a message and allow you to answer Yes, No, Cancel, Retry or Ignore.
3) Select Case Statements,
Select Case Statements tells the code what to do based upon the users input.
3) Sub Procedure Call,
Procedure call method used to simplified the process call and re-usability .
Note*: Please Enter few remarks below, if code is helpful for you.
Thanks.!
Comments
Post a Comment