This is actually part of many scripts I had created way back in 2002/2003 using VBScript to automate various Windows tasks (I wasn’t in the web development field by the time ;- ) . Today, I came across this piece of script on my computer and though of sharing with you.
Well, there is nothing really fancy, I have put the MSScript.ocx active-x control to use. It’s eval function can evaluate most complex math expressions easily. So here is how to create the calculator:
1. Open Notepad and jot down the following 4 lines of code in it:
Set SC = CreateObject("ScriptControl") SC.Language = "VBScript" Val = InputBox("Enter simple or advanced expression to evaluate." & vbCrLf & vbCrLf & "Example:" & vbCrLf & vbCrLf & "(5+5)/2" & vbCrLf & vbCrLf & "or" & vbCrLf & vbCrLf & "Log(99)/2*25+3-(10^2 Mod 5)-Sin(60)+Tan(90)+2") If Trim (Val) <> "" Then MsgBox "Answer = " & SC.Eval(Val),,"Result"
2. Now save the file as calculator.vbs by selecting All Files from Save as type combo box. Note that vbs extension in the file name to denote that this file is vbscript and is to be run by Windows Scripting Host (wscript.exe).
3. Double click the saved file and there you are.
Have fun ;-)