Adding values from drop down menus

  • 14 years ago

    I have an html form with 14 drop down menus.  Each with two answers of values of 0 and one value of 1.

    0equals an incorrect answer. 1 equals a correct answer.

    Therefore if the user answers all questions correctly and I add all the values together they get:

    11111111111111

    I can then work out the percentage of correct answers very easily.

    Working out the % if a user gets 6 or 7 right is harder because there are literally hundreds of combinations of 1 and 0's.

    Question is how do I work out how many correct answers the user has got as I cant add together variables.

    Many Thanks

    David

  • 14 years ago

    no worries guys.  worked it out.

  • 14 years ago

    hi David.

    you must count the "0" and the "1" in the result string and the  do the ratio

    dim

    StrResult ' may be any combination from 00000000000000 to 11111111111111

    dim

    counter ' used to scan the result string

    dim

    ZeroCounter , OneCounter

    ZeroCounter = 0

    for

    counter = 1 to len(StrResult)

    if mid(StrResult, counter, 1) = "0" then

    ZeroCounter = ZeroCounter + 1

    end if

    next

    ' number of "1" in the result

    OneCounter = 14 - ZeroCounter

     

  • 14 years ago

    sorry , i haven't read this post but can you write the code you used to fix your problem ?

     

    Serval

     

     

  • 14 years ago

    Ho ho ,

    very very good idea the split method :-)

    so in classic asp we'll have

    TheOnes =

    UBound(Split("11111110000001", "1")

    TheZeros =

    UBound(Split("11111110000001", "0")

    Serval

     

Post a reply

Enter your message below

Sign in or Join us (it's free).

Contribute

Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“A computer is a stupid machine with the ability to do incredibly smart things, while computer programmers are smart people with the ability to do incredibly stupid things. They are, in short, a perfect match” - Bill Bryson