Day 9 Radio Button Example (pages 286-287)

1. John Vlcek Guest

## Day 9 Radio Button Example (pages 286-287)

In the Day 9 Radio Button example, the script adds together the values passed by the 4 groups of radio buttons in preparation for averaging them. Or rather, it is SUPPOSED to add them together. The statement "iSum = iQuestion1 + iQuestion2 + iQuestion3 + iQuestion4" for me CONCATENATES the numbers together rather than adding them! For example, if all 4 values are "2" I get a result of "2222" rather than "8". Now I have looked long and hard at my code and it IS identical to the example in the book, and it works correctly with any other mathematical sign. I can get this code to work correctly for me by adding a zero to the beginning of the expression, like this: "iSum = 0 + iQuestion1 + iQuestion2 + iQuestion3 + iQuestion4" but somehow I don&#039t really think that should be necessary. I am kind of new at this; I hope I am not missing something obvious here!<BR><BR>Thanks,<BR>John Vlcek

2. Ed Guest

## RE: Day 9 Radio Button Example (pages 286-287)

Are you using JScript or VBScript?

3. John Vlcek Guest

## RE: Day 9 Radio Button Example (pages 286-287)

I double checked, and it IS VBScript, not JScript. I had the same problem with day 9 exercise 1 (the calculator-type form). Once again:<BR><BR>Response.Write(iNum1 & " + " & iNum2 & " = " & (iNum1 + iNum2))<BR><BR>would concatenate iNum1 and iNum2 together instead of adding them, while subtraction, multiplication, etc. would work fine. And once again, changing the expression to (0 + iNum1 + iNum2) would solve the problem!

4. Dean C Guest

## RE: Day 9 Radio Button Example (pages 286-287)

I ran into the same issue. The problem is that the variable type for the inputs are strings! (try "TypeName(iQuestion1)" ). The + operator will add integers and will concatenate strings. In your resolve, adding the 0 forces automatic type conversion. A better way (and also good practice) would be to cast the type as you collect the data from the request object. For example... "iQuestion1 = Int(Request("Question1"))". In this way you won&#039t have to cast it evertime you use the value in the rest of your script.<BR><BR>Cheers,<BR>Dean C

5. Dean C Guest

## RE: Day 9 Radio Button Example (pages 286-287)

Ooops...To cast the type use Cint() ie "iQuestion1 = Cint(Request("Question1"))". The casting functions are on page 726.<BR><BR>Cheers,<BR>Dean C

6. John Vlcek Guest