Results 1 to 5 of 5

Thread: Basic Calculator

  1. #1

    Thread Starter
    New Member
    Join Date
    Mar 2001
    Posts
    2

    Question

    Hi guys

    I need a Calculator in VB script that has just basic

    + - * / =

    can someone help me please...
    Thanks in Advance
    Attached Images Attached Images  

  2. #2
    Addicted Member Active's Avatar
    Join Date
    Jan 2001
    Location
    Lat: 13° 4' 46" N, Long: 80° 15' 20" E
    Posts
    209
    Use the Eval Function.

    Eg:

    Dim answer,strCalc

    StrCalc = "2+(5*10)"

    answer = Eval(strCalc)

    answer will now have 52.
    If you can't beat your computer at chess, try kickboxing !!!
    [Download Tag Editing Tools.]

  3. #3

    Thread Starter
    New Member
    Join Date
    Mar 2001
    Posts
    2

    Talking Thanks

    is it possible that you give me the complete script.

    I'm new to VB Script.

    Dim answer,strCalc

    StrCalc = "2+(5*10)"

    answer = Eval(strCalc)

    answer will now have 52.

    thanks
    Last edited by jafang; Mar 14th, 2001 at 02:23 AM.

  4. #4
    Fanatic Member Jerry Grant's Avatar
    Join Date
    Jul 2000
    Location
    Dorset, UK
    Posts
    810

    Cool

    Try this:
    Code:
    <HTML>
    <HEAD>
    <META NAME="GENERATOR" Content="Microsoft Visual Studio 6.0">
    <TITLE>Simple calculator</TITLE>
    <SCRIPT language="VBscript">
    Function DoCalc()
    	Dim strData, num1, num2, op
    	
    	num1 = oForm.oNumber1.Value
    	num2 = oForm.oNumber2.Value
    	op = oForm.oOperation.options(oForm.oOperation.selectedIndex).value
    
    	If isnumeric(num1) And isnumeric(num2) Then
    		If  num2 = 0 And op = "/" Then
    			MsgBox "Cannot divide by zero!", ,"Simple calculator"
    		Else
    			strData = num1 & op & num2
    			oForm.oResult.value = Eval(strData)
    		End If
    	Else
    		MsgBox "Cannot calculate the inputs given!", ,"Simple calculator"
    	End If
    End Function
    </SCRIPT>
    </HEAD>
    <BODY>
    <FORM name="oForm">
    <TABLE cellSpacing=1 cellPadding=1 width="75%" border=1>
      
      <TR>
        <TD>First Number</TD>
        <TD>Operation</TD>
        <TD>Second Number</TD>
        <TD>Result</TD></TR>
      <TR>
        <TD><INPUT name="oNumber1"></INPUT></TD>
        <TD>
    		<SELECT name=oOperation> 
    			<OPTION value="+" selected>Add</OPTION>
    			<OPTION value="-">Subtract</OPTION>
    			<OPTION value="*">Muliply</OPTION>
    			<OPTION value="/">Divide</OPTION>
    		</SELECT>
    	</TD>
        <TD><INPUT name="oNumber2"></TD>
        <TD><INPUT name="oResult"></TD>
      </TR>
    </TABLE>
    <P><INPUT type="button" value="Calc" onClick="DoCalc"></P>
    </FORM>    
    
    </BODY>
    </HTML>
    It will need a bit more work, but shows the basics.
    Jerry Grant................tnarG yrreJ
    Website: <JG-Design></.net>
    Email: [email protected]
    Working towards a bug free world......
    (Not a Microsoft employee)

  5. #5
    Frenzied Member Mark Sreeves's Avatar
    Join Date
    Nov 1999
    Location
    UK
    Posts
    1,845
    Mark
    -------------------

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width