×

Loading...
Ad by
  • 最优利率和cashback可以申请特批,好信用好收入offer更好。请点链接扫码加微信咨询,Scotiabank -- Nick Zhang 6478812600。
Ad by
  • 最优利率和cashback可以申请特批,好信用好收入offer更好。请点链接扫码加微信咨询,Scotiabank -- Nick Zhang 6478812600。

you look like a girl programmer

<%
dim col1(2)
col1(0)=0
for i=1 to 2
col1(i)=TRIM(Request("col1(i)"))
col1(i)=cINT(col1(i))
total1=col1(i)+col1(i-1)
next
%>
-------------------------------------------------------
considering change to following code
1)
dim col1(2) means you have 3 elements
col1(0), col1(1), col1(2)

2)
before doing CINT, you have to check the
parameter, make sure it's Numeric, if it;s
not, say, a non-numeric string or Null, you
will get the error : Type Mismatch

3) this is the right way
total1 = total1 + col1(i)
-------------------------------------------------------
<%
dim col1(2)
total1 = 0
for i=1 to 2
col1(i)=TRIM(Request("col1(" & i & ")"))
if isnumeric(col1(i)) then
col1(i)=cINT(col1(i))
else
col1(i)=0
end if
total1 = total1 + col1(i)
next
%>
Report

Replies, comments and Discussions:

  • 工作学习 / IT技术讨论 / Web programmer take a look please. Thank you very much. Array can't be converted into number?
    本文发表在 rolia.net 枫下论坛Hi,freinds. I write a simple code as following:
    ----------------------------------------------
    <%
    dim col1(2)
    col1(1)=TRIM(Request("col1(1)"))
    col1(2)=TRIM(Request("col1(2)"))
    col1(1)=cINT(col1(1))
    col1(2)=cINT(col1(2))
    total1=col1(1)+col1(2)

    %>
    <html>
    <body>
    <%=col1(1)%><br>
    <%=col1(2)%><br>
    <%=total1%><br>
    </body>
    </html>
    -----------------------------------------------
    It works. When I input 2 number in the table of another webpage, it gives right answer.
    But because the involved row is actually much larger than 2. So I want to use FOR looping
    to simplize the code. I write as following:
    ------------------------------------------
    <%
    dim col1(2)
    col1(0)=0
    for i=1 to 2
    col1(i)=TRIM(Request("col1(i)"))
    col1(i)=cINT(col1(i))
    total1=col1(i)+col1(i-1)
    next
    %>
    <html>
    <body>
    <% for i=1 to 2%>
    <%=col1(i)%>
    <%next%>
    <%=total1%>
    </body>
    </html>
    ---------------------------
    But it doesn't work.IE displays:"Type mismatch: 'cINT' "Who can tell me how to fix it?
    Thanks a lot.更多精彩文章及讨论,请光临枫下论坛 rolia.net
    • 感觉想数组溢出了,dim col(2)好象只有col(1) 和col(0),没有col(2)的
      • You are wrong. Dim col1(2) has 3 variable3 col1(0),col1(1),col1(2).
    • 俺没用过ASP,不过你这错误倒也明显
      就是既然定义了dim col1(2),就说明只有两个元素喽。但是你又接着写col1[0]=0, col1[1]=x, col1[2]=y, 当然就不对啦。想求和,在for外面定义一个sum=0; 然后在for里面sum+=col1[i]即可。
    • the problem is col1(i)=TRIM(Request("col1(i)"))
      you should use
      col1(i)=TRIM(Request("col1(" & i & ")"))
      • good try. But it doesn't work. I think problem occurs in the data type within the cINT. It looks like cINT (clo1(i)) is wrong accroding to the IE response.
    • the array index is begin from 0. So you don't have col1(2).
      • the definition of C and VB is different.
    • you look like a girl programmer
      <%
      dim col1(2)
      col1(0)=0
      for i=1 to 2
      col1(i)=TRIM(Request("col1(i)"))
      col1(i)=cINT(col1(i))
      total1=col1(i)+col1(i-1)
      next
      %>
      -------------------------------------------------------
      considering change to following code
      1)
      dim col1(2) means you have 3 elements
      col1(0), col1(1), col1(2)

      2)
      before doing CINT, you have to check the
      parameter, make sure it's Numeric, if it;s
      not, say, a non-numeric string or Null, you
      will get the error : Type Mismatch

      3) this is the right way
      total1 = total1 + col1(i)
      -------------------------------------------------------
      <%
      dim col1(2)
      total1 = 0
      for i=1 to 2
      col1(i)=TRIM(Request("col1(" & i & ")"))
      if isnumeric(col1(i)) then
      col1(i)=cINT(col1(i))
      else
      col1(i)=0
      end if
      total1 = total1 + col1(i)
      next
      %>
      • Great! It works. Rootbear, you solved the problem for me. Thanks you very much.Other friends, thank you anyway, and check out how Rootbear solve this problem.