Change response to only respond one set of values

前端 未结 3 1216
傲寒
傲寒 2021-01-29 08:43

I am very novice at asp. Here is my code:

response.write(\"

        
相关标签:
3条回答
  • 2021-01-29 09:16

    Not sure I should be answering this, but to loop and only write out on the even iteration use Mod() to test the remainder.

    response.write("<script>")
    dim counter: counter = 0
    do until rs.EOF
      for each x in rs.Fields
        counter = counter + 1
        'Use Mod() to check counter is even
        If counter Mod 2 = 0 Then response.write "var CC" & counter & "=" & x.value & ";"
      next
      rs.MoveNext
    loop
    response.write("</script>")
    

    Useful links

    • The Magical Mod Function
    0 讨论(0)
  • 2021-01-29 09:24

    Ad an IF statement, based on your counter.

    for each x in rs.Fields
        counter = counter + 1
        if(counter = 1) then
          response.write "var CC" & counter & "=" & x.value & ";"
        end if
    next
    
    0 讨论(0)
  • 2021-01-29 09:27

    Try this

    response.write("<script>")
    dim counter: counter = 0
    do until rs.EOF
      for each x in rs.Fields
        counter = counter + 1
        if IsNumeric(x.value) then
            response.write "var CC" & counter & "=" & x.value & ";"
        end if
      next
      rs.MoveNext
    loop
    response.write("</script>")
    

    The trick is to check "If IsNumeric" then do what you want.

    0 讨论(0)
提交回复
热议问题