我该如何解决这个问题? Microsoft VBScript 运行时错误“800a0006”溢出 /Variable.asp,第 27 行 有用的链接

问题描述

这是我的代码。我正在制作一个网站,可以解决我的要求的二次公式。并且它需要从一个表单中调用至少三个变量。

<form action="Variable.asp" id="arrays" method="get">
    <label for="category">A: </label><br>
    <input name="aname" id="aname"><br>

    <label for="category">B: </label><br>
    <input name="bname" id="bname"><br>

    <label for="category">C: </label><br>
    <input name="cname" id="cname"><br>
    <input type="submit">

</form>
<%
    Function solvex1(a,b,c)
        x1 = (b * b)
        x1 = x1 - (4 * (a * c))
        x1 = Sqr(x1)
        x1 = -b + x1
        x1 = x1 / (2 * a)
        x1 = CInt(x1)
        x1 = x1
    End Function

    Function solvex2(a,c)
        x2 = (b * b)
        x2 = x2 - (4 * (a * c))
        x2 = Sqr(x2)
        x2 = -b - x2
        x2 = x2 / (2 * a)
        x2 = CInt(x2)
        x2 = x2
    End Function


    Response.Write("Here is your answer: <br>")
    Response.Write("X1 = ")
    Response.Write(solvex1(Request.Form("aname"),Request.Form("bname"),Request.Form("cname")) & "<br>")
    Response.Write("X2 = ")
    Response.Write(solvex2(Request.Form("aname"),Request.Form("cname")) & "<br>")
%>

解决方法

主要问题是您不会从函数调用中返回任何内容,但您希望在 Response.Write() 调用中输出它们的值。

尝试更改函数定义以显示您想要返回值。下面是重写的 solvex1() 函数以返回 x1 的值:


Function solvex1(a,b,c)
    Dim x1
    x1 = (b * b)
    x1 = x1 - (4 * (a * c))
    x1 = Sqr(x1)
    x1 = -b + x1
    x1 = x1 / (2 * a)
    x1 = CInt(x1)
    x1 = x1
    'Return the value from the function.
    solvex1 = x1
End Function

要从函数返回一个值,请将其分配给函数的名称。

此外,强烈建议在执行任何数学计算之前检查您传递给函数的值是否是有效的数值。


有用的链接