Web Analytics Made Easy -
StatCounter Percentages. - CodingForum

Announcement

Collapse
No announcement yet.

Percentages.

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Percentages.

    Is this even possible what I am doing?

    <% = FormatPercent(rsQuiz("Score")/("Question_Asked"))>
    Kind regards,
    Mike Hughes

  • #2
    Yes, it is. Assuming both are numeric values. I think you may have a syntax error, not closing your ASP tag.


    FormatPercent Function


    Code:
    <%= FormatPercent(rsQuiz("Score")/("Question_Asked")) %>
    Whats the point of a signature?

    Comment


    • #3
      Thanks. Both values are integers. But I am still getting this


      Code:
      Error Type:
      Type mismatch: '[string: "Question_Asked"]'
      /Test/Quiz/see_all.asp, line 83
      Can you help a bitmore?

      Code:
      <td width="212" height="43" bgcolor="#CCCCCC" align="center"><font size="2" color="#000000"><%= FormatPercent(rsQuiz("Score")/("Question_Asked")) %></font></td>
      Kind regards,
      Mike Hughes

      Comment


      • #4
        How blindingly obvious.

        "Question_Asked" is simply a string. "Question_Asked" needs to be either a variable with a numeric datatype or put in the number. Perhaps it just needs to be...

        Code:
        <%= FormatPercent(rsQuiz("Score")/(Question_Asked)) %>
        or perhaps you meant that to be getting from the db as well...

        Code:
        <%= FormatPercent(rsQuiz("Score")/rsQuiz("Question_Asked")) %>
        Last edited by CrzySdrs; Aug 2, 2005, 01:12 PM.
        Whats the point of a signature?

        Comment


        • #5
          This one got it. Thanks.


          <%= FormatPercent(rsQuiz("Score")/rsQuiz("Question_Asked")) %>
          Kind regards,
          Mike Hughes

          Comment


          • #6
            To avoid runtime error if the database fields are null, empty or not numeric or division by zero occurs:
            Code:
            <%
            Function Percent(ByVal score, ByVal total)
              If IsNumeric(score) And IsNumeric(total) And total <> 0 Then
                 Percent = FormatPercent(score/total)
              Else
                 Percent = "-"
              End If
            End Function
            %>
            ...
            <%= Percent(rsQuiz("Score"), rsQuiz("Question_Asked")) %>
            Last edited by glenngv; Aug 2, 2005, 11:40 PM.
            Glenn
            vBulletin Mods That Rock!

            Comment


            • #7
              it is something like <?= $_some_server_var ?> in php

              Comment


              • #8
                Originally posted by cf2sg
                it is something like <?= $_some_server_var ?> in php
                Glenn
                vBulletin Mods That Rock!

                Comment


                • #9
                  Glen - thanks for this. Your script helped loads.
                  Kind regards,
                  Mike Hughes

                  Comment

                  Working...
                  X