ASP之vbscript笔记1

通过inputBox输入计算两个数的和

 

页面截图:

 

通过inputBox输入计算两个数的和源文件:

<html> 
    <head> 
        <title>
通过inputBox输入计算两个数的和</title> 
    </head> 
    <body> 
     
        <SCRIPT LANGUAGE="VBScript"> 
    <!--  

        ' The next line of code executes when the script tag is parsed. 
        Call
 PrintWelcome 
 
        Sub PrintWelcome 
            Dim h 
 
            h = Hour(Now) 
            If h < 12 then  
                Document.Write "
早上好!" 
            ElseIf h < 17 then  
                Document.Write "
下午好!" 
            Else  
                Document.Write "
晚上好!" 
            End If 
            Document.Write "
欢迎进入 VBScript 世界。" 
            Document.Write("<br/>"
            Document.Write "
现在是 :"  
            Document.Write("<input name='nowTime' type='text' size='30'  style='border:0;background:transparent;color: #FF0000;' readonly='readonly'>"
 
        End Sub 
    --> 
    </SCRIPT> 
     
<!--
时钟--> 
    <script language=vbs> 
    function myTime() 

        nowTime.value=date&" "&time 
        t=setTimeout("myTime()",1000
    end function 
    window_onload=myTime 
    </script> 
     
    <p>--------------------------------------------------</P> 
        <script language="vbscript"> 
            dim num1,num2,result 

           
 sub
 Add() 
                num1=inputBox("
请输入第一个数","标题:num1",0,700,600
                do while num1=Empty or (not isNumeric(num1)) 
                    MsgBox("
你输入有误"
                    num1=inputBox("
请输入第一个数"
                loop 
                 
                num2=inputBox("
请输入第二个数"
                do while isEmpty(num2) or (not isNumeric(num2)) 
                    MsgBox("
你输入有误"
                    num2=inputBox("
请输入第二个数"
                loop 
                 
                result=cint(num1)+num2 
                 
                MsgBox("
两个数的和是" & result) 
            end sub 
        </script> 
        <input type="button" onclick="Add()" value="
加法计算"></input> 
    </body> 
</html> 

 

通过inputBox输入计算两个数的和

 

通过sub计算两个数的和源码:

<html> 
<head> 
    <title>
通过sub计算两个数的和</title> 
    <script type="text/vbscript"> 
        sub equal_onclick() 

            form1.result.value=cint(form1.num1.value)+form1.num2.value 

        end sub
    </script> 
</head> 
<body> 
    <form name="form1" action=""> 
    <input type="text" name="num1"></input>&nbsp;+&nbsp; 
    <input type="text" name="num2"></input> 
    <input type="button" name="equal" value="="></input> 
    <input type="text" name="result"></input> 
    </form> 
</body> 
</html> 

 

通过sub计算两个数的和

 

通过sub计算两个数的和源码:

<html> 
<head> 
    <title>
通过sub计算两个数的和</title> 
    <script type="text/vbscript"> 
        function Add() 

            form1.result.value=cint(form1.num1.value)+form1.num2.value 

        end function 
    </script> 
</head> 
<body> 
    <form name="form1" action=""> 
    <input type="text" name="num1"></input>&nbsp;+&nbsp; 
    <input type="text" name="num2"></input> 
    <input type="button" onclick="Add()" value="="></input> 
    <input type="text" name="result"></input> 
    </form> 
</body> 
</html> 

 

下拉框式的加减乘除运算器

 

界面截图:

下拉框式的加减乘除运算器源码:

<!-- 
名称:下拉框式的加减乘除运算器 
功能:实现加减乘除法运算 
Author:
罗维 
时间:2011-9-19 
--> 
 
<html> 
<head> 
    <title>
下拉框式的加减乘除运算器</title> 
    <script type="text/vbscript"> 
        dim num1,num2,num3 

    '-------------------------------------------------- 
        function
 getnum()    '
获取输入框的数字 
            num1=cDbl(form1.num1.value) 
            if num1=Empty or (not isNumeric(num1)) then 
                MsgBox("
第一个输入框的数字有误"
                exit function 
            end if 
            num2=cDbl(form1.num2.value) 
            if num1=Empty or (not isNumeric(num2)) then 
                MsgBox("
第二个输入框的数字有误"
                exit function 
            end if 
            getnum=true 
        end function 
    '--------------------------------------------------     
        function Add()    '
加法运算 
            if getnum then 
                Add=num1+num2 
            else 
                exit function 
            end if 
        end function 
    '--------------------------------------------------     
        function Substract()    '
减法运算 
            if getnum then 
                Substract=num1-num2 
            else 
                exit function 
            end if 
        end function 
    '--------------------------------------------------     
        function Multiply()    '
乘法运算 
            if getnum then 
                Multiply=num1*num2 
            else 
                exit function 
            end if 
        end function 
    '--------------------------------------------------     
        function Divide()    '
除法运算 
            if getnum then 
                if(num2=0then 
                    MsgBox "
被除数为零!" 
                    exit function 
                end if 
                Divide=num1/num2 
            else 
                exit function 
            end if 
        end function 
    '--------------------------------------------------     
        function opt() 
'
方式一 
'            if form1.operate.value="+" then 
'                form1.result.value=Add 
'            elseif form1.operate.value="-" then 
'                form1.result.value=Substract 
'            elseif form1.operate.value="*" then  
'                form1.result.value=Multiply 
'            else form1.operate.value="/"  
'                if Divide>0 and Divide<1 then 
'                    form1.result.value="0"+CStr(Divide) 
'                elseif Divide<0 and Divide>-1 then 
'                    form1.result.value="-0"+Mid(CStr(Divide),2) 
'                else 
'                    form1.result.value=Divide 
'                end if 
'            end if 
'
方式二 
            select case form1.operate.value 
                case "+" 
                    form1.result.value=Add 
                case "-" 
                    form1.result.value=Substract 
                case "*" 
                    form1.result.value=Multiply 
                case "/" 
                    if Divide>0 and Divide<1 then 
                        form1.result.value="0"+CStr(Divide) 
                    elseif Divide<0 and Divide>-1 then 
                        form1.result.value="-0"+Mid(Divide,2
                    else 
                        form1.result.value=Divide 
                    end if 
            end select 
        end function 
    </script> 
</head> 
<body> 
    <h1>
下拉框式的加减乘除运算</h1> 
    <form name="form1" action=""> 
    <input type="text" name="num1" ></input> 
    <select size="1" name="operate"> 
        <option value="+" >+</option> 
        <option value="-">-</option> 
        <option value="*">*</option> 
        <option value="/">/</option> 
    </select> 
    <input type="text" name="num2"></input> 
    <input type="button" name="equal" value="=" onclick="opt"></input> 
    <input type="text" name="result"></input> 
    </form> 
</body> 
</html> 

原文地址:https://www.cnblogs.com/luowei010101/p/2181559.html