0

Here's my Code. I'm making a website that solves for a quadratic formula for my requirement. And it requires to call at least three variables from a form.

<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,b,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("bname"), Request.Form("cname")) & "<br>")
%>
user692942
  • 16,398
  • 7
  • 76
  • 175
MinMin
  • 1
  • 1
  • 1
    https://stackoverflow.com/questions/789663/no-clue-overflow-microsoft-vbscript-runtime-error-800a0006?rq=1 here someone had also an 800a0006 runtime error. Maybe the variable "a" is zero? – 3r1c Apr 21 '21 at 05:58
  • I've already seen that but it didn't help. When I also add a value to "a" still gets the error. – MinMin Apr 21 '21 at 06:00
  • Before doing any mathematical calculations make sure all the variables you pass into the function are numeric, you can use a combination of `IsNumeric()` to check and `CInt()` or `CLng()` to convert them. – user692942 Apr 21 '21 at 06:56
  • See this too: [Cint overflow error when value exceeds 100,000+](https://stackoverflow.com/questions/8967448/cint-overflow-error-when-value-exceeds-100-000) – Flakes Apr 21 '21 at 09:10
  • I have solved the issues but if I start it returns Microsoft VBScript runtime error '800a0006' Overflow because there where no Values on the variables but when I entered Values using the user input it solves the error. Don't know how to add values before user input tho. – MinMin Apr 21 '21 at 17:36
  • The form method is `get`, so the `request` values have to be accessed using `Request.Querystring("fieldname")` or simply `Request("fieldname")` which will work for both `get` and `post` methods. – Flakes Apr 22 '21 at 05:11
  • If you enclose all the `Response.Write`s within a check like `If Request("aname")<> "" Then` you won't get the initial errors. – Flakes Apr 22 '21 at 05:13

1 Answers1

1

The main issue is you don’t return anything from your function calls, but you expect to output their value in a Response.Write() call.

Try changing the function definitions to show you want to return the value. Here is the solvex1() function rewritten to return the value of 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

To return a value from a function assign it to the name of the function.

Also, would highly recommend checking the values you pass into the function are valid numeric values before any mathematical calculations are performed.


Useful Links

user692942
  • 16,398
  • 7
  • 76
  • 175