Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

What is wrong with this ASP ???

Explorer ,
Feb 07, 2011 Feb 07, 2011

<%
    a = Request.Form("size")
    b = Request.Form("lights")
    c = Request.Form("logo")
    d = Request.form("zone")
    z = (a + b + c + d)
    Response.Write z
    %>

Z will only out put the values of a,b,c,d it will not add them together?

You can try it here...http://bigfootdesigns.com/web-dev/heliwagon/test.asp

thanks

B

TOPICS
Server side applications
768
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Feb 07, 2011 Feb 07, 2011

myb it cause by your a,b,c,d data type. That why it didnt add the value.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Feb 07, 2011 Feb 07, 2011

What kind of answer is that? That does not help!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Feb 08, 2011 Feb 08, 2011

>myb it cause by your a,b,c,d data type. That why it didnt add the value.

VBScript has only one datatype - Variant. Form field values need to be converted to numeric before you can add them.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Feb 08, 2011 Feb 08, 2011

I can't get it to work. Can you please provide a working example of the code that I am trying to write. I am not a programmer! CInt willnot work I get an overflow error so I tried Int and I still get the following..

Dolly500
Lights100
Logo100
Zone600
Total:                                                                                             500100100600

a combination of the actual numbers not the sum of the number.

<%
    Dim a, b, c, d, z
    a = Request.Form ("size")
    b = Request.Form ("lights")
    c = Request.Form ("logo")
    d = Request.Form ("zone")
    z = (a + b + c + d)
    Response.Write (Int(z))

thanks

B

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Feb 08, 2011 Feb 08, 2011

You need to convert the values before you add them, not after:

a = cint (Request.Form ("size"))

etc....

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Feb 08, 2011 Feb 08, 2011

Ok thanks that makes sense now and I have it working.

<%
    a = cint (Request.Form ("size"))
    b = cint (Request.Form ("lights"))
    c = cint (Request.Form ("logo"))
    d = cint (Request.Form ("zone"))
    z = (a + b + c + d)
    Response.Write z
    %>

thanks

B

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Feb 08, 2011 Feb 08, 2011
LATEST

>VBScript has only one datatype - Variant. Form field values need to be converted to numeric before you can add them.

owh. okay thanks. im newbie in programming. thanks for the info.

>>>themachien : sorry that i cant help. im still new in programming

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Feb 08, 2011 Feb 08, 2011

I can get the code to work if I replace the Request.Form with a number. It will total it correctly like this

<%
    a = 4
    b = 4
    c = 4
    d = 4
    z = (a + b + c + d)
    Response.Write z
    %>

it will give me 16

but why will it only display the Request.Form values and not total them???

B

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Feb 08, 2011 Feb 08, 2011

VBScript has only one datatype - Variant. Form fields are handled as text fields. In VBscript, the '+' operator serves as arithemetic additional as well as string concatenation. So if you want to use arithmatic operators on form fields, you must first convert them to numeric values. Use the cint() function.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines