compare variables that contain text

Discussion in 'ASP General' started by Peter, Sep 24, 2003.

  1. Peter

    Peter Guest

    Hi,

    I was wondering how do you compare variables that contain text strings in
    ASP.

    When I use the following If.. Then statement:

    If Rs("StyleNo") <> arrStyleNo(aCount) Then


    I always get the following error when I try to browse the page:

    Error Type:
    (0x80020009)
    Exception occurred.


    Thanks.

    Peter
     
    Peter, Sep 24, 2003
    #1
    1. Advertising

  2. Peter

    Ken Schaefer Guest

    Does Rs("StyleNo") contain a NULL value?

    If so, do something like:

    If CStr(RS.Fields("StyleNo").Value & "") <> CStr(arrStyleNo(aCount)) then
    ...
    End If

    Cheers
    Ken

    "Peter" <> wrote in message
    news:bkr1ib$...
    : Hi,
    :
    : I was wondering how do you compare variables that contain text strings in
    : ASP.
    :
    : When I use the following If.. Then statement:
    :
    : If Rs("StyleNo") <> arrStyleNo(aCount) Then
    :
    :
    : I always get the following error when I try to browse the page:
    :
    : Error Type:
    : (0x80020009)
    : Exception occurred.
    :
    :
    : Thanks.
    :
    : Peter
    :
    :
     
    Ken Schaefer, Sep 24, 2003
    #2
    1. Advertising

  3. Peter

    Curt_C [MVP] Guest

    Try a CStr() around each to force the type

    --
    ----------------------------------------------------------
    Curt Christianson (Software_AT_Darkfalz.Com)
    Owner/Lead Designer, DF-Software
    http://www.Darkfalz.com
    ---------------------------------------------------------
    ...Offering free scripts & code snippits for everyone...
    ---------------------------------------------------------


    "Peter" <> wrote in message
    news:bkr1ib$...
    > Hi,
    >
    > I was wondering how do you compare variables that contain text strings in
    > ASP.
    >
    > When I use the following If.. Then statement:
    >
    > If Rs("StyleNo") <> arrStyleNo(aCount) Then
    >
    >
    > I always get the following error when I try to browse the page:
    >
    > Error Type:
    > (0x80020009)
    > Exception occurred.
    >
    >
    > Thanks.
    >
    > Peter
    >
    >
     
    Curt_C [MVP], Sep 24, 2003
    #3
  4. Peter

    Peter Guest

    Hi,

    Thanks for the advice. But I found out where the problem was coming from.

    The error "Error Type (0x80020009) Exception occurred" came from having the
    "If..Then" statement come after the Rs.Movenext. When the object
    Rs.Movenext went past the last record , Rs("StyleNo") did not contain
    anything in it any more. So it came up with an error. Here is more of the
    code that I was working on.

    SQLstmt = "SELECT * FROM tblQuotation WHERE UserName='" &
    Session("username") & "' ORDER BY StyleNo, Color"
    Set Rs = conn.execute(SQLstmt)
    Do While Not Rs.EOF
    Response.Write "Your Contract No is " & Rs("ContractNo") & "<br>"
    Response.Write "<table border='1' width='200'>"
    aCount = aCount + 1
    arrStyleNo(aCount) = Rs("StyleNo")
    arrPic(aCount) = Rs("Pic")
    Response.Write "<tr><td><B>Style No</B></td><td>" & (arrStyleNo(aCount)) &
    " " & Rs("Color") & "</td></tr>"
    Response.Write "<tr><td colspan='2' align='right'><A HREF='" &
    (arrPic(aCount)) & "'><IMG SRC='" & (arrPic(aCount)) & "' width='153'
    height='230'></A></td></tr>"
    Response.Write "<tr><td><B>Price</B></td><td> $" & Rs("UnitPrice") &
    "</td></tr>"
    Response.Write "<tr><td><B>Fabrication</B></td><td>" &Rs("Desc") &
    "</td></tr>"
    Response.Write "</table>"
    Response.Write "<BR><BR>"
    Rs.Movenext
    If Rs("StyleNo") <> arrStyleNo(aCount) Then
    bCount = aCount
    aCount = 0
    For iCounter = 1 to bCount
    Response.Write "Hello"
    Next
    Else
    End If
    Loop
    Rs.Close
    Set Rs = Nothing


    In order to solve the problem , I took the If..Then statement an put it
    before the Rs.Movenext and I also added more arrays to store the records.
    The records of the database would be compared by using the arrays rather
    than comparing with Rs object directly. The code that works is as follows:


    SQLstmt = "SELECT * FROM tblQuotation WHERE UserName='" &
    Session("username") & "' ORDER BY StyleNo, Color"
    Set Rs = conn.execute(SQLstmt)
    Do While Not Rs.EOF
    aCount = aCount + 1
    arrStyleNo(aCount) = Rs("StyleNo")
    arrColor(aCount) = Rs("Color")
    arrDesc(aCount) = Rs("Desc")
    arrPic(aCount) = Rs("Pic")
    arrT1(aCount) = Rs("T1")
    arrT2(aCount) = Rs("T2")
    arrT3(aCount) = Rs("T3")
    arrUnitPrice(aCount) = Rs("UnitPrice")
    arrQty(aCount) = arrT1(aCount) + arrT2(aCount) + arrT3(aCount)
    arrAmt(aCount) = arrQty(aCount) * arrUnitPrice(aCount)
    Rs.MoveNext
    Loop
    Rs.Close
    Set Rs = Nothing
    Response.Write "<table border='0' width='800'>"
    For iCounter = 1 to aCount
    If NOT arrStyleNo(iCounter -1) = arrStyleNo(iCounter) Then
    Response.Write "<tr><td><table border = '1' width=800><tr><td><B>Style
    No</B></td><td><B>Color</B></td><td><B>Fabrication</B></td><td><B>T1</B></td
    ><td><B>T2</B></td><td><B>T3</B></td><td><b>Qty</b></td><td><B>Unit

    Price</B></td><td><B>Amount</B></td></tr>"
    End If
    Response.Write "<tr><td>" & arrStyleNo(iCounter) & "</td><td>" &
    arrColor(iCounter) & "</td><td>" & arrDesc(iCounter) & "</td><td>" &
    arrT1(iCounter) & "</td><td>" & arrT2(iCounter) & "</td><td>" &
    arrT3(iCounter) & "</td><td>" & arrQty(iCounter) & "</td><td> $" &
    arrUnitPrice(iCounter) & "</td><td> $" & arrAmt(iCounter) & "</td></tr>"
    If arrStyleNo(iCounter) <> arrStyleNo(iCounter + 1) Then
    Response.Write "<tr><td colspan='9'><table><tr>"
    For jCounter = cCount to iCounter
    Response.Write "<td><a href='" & arrPic(jCounter) & "'><img src='" &
    arrPic(jCounter) & "' width='153' height='230'></a></td>"
    Next
    cCount = jCounter
    Response.Write "</tr></table></td></tr></td></tr></table><tr><td
    colspan='9'>&nbsp;</td></tr><tr><td colspan='9'>&nbsp;</td></tr>"
    End If
    Next
    Response.Write "</table><BR><BR>"

    End If


    I basically placed all of the records into arrays first and then I retrieved
    and compared the contents of the arrays using the "For..Next" loops.

    Thanks for all the advice.


    "Curt_C [MVP]" <software_AT_darkfalz.com> ¦b¶l¥ó
    news:% ¤¤¼¶¼g...
    > Try a CStr() around each to force the type
    >
    > --
    > ----------------------------------------------------------
    > Curt Christianson (Software_AT_Darkfalz.Com)
    > Owner/Lead Designer, DF-Software
    > http://www.Darkfalz.com
    > ---------------------------------------------------------
    > ..Offering free scripts & code snippits for everyone...
    > ---------------------------------------------------------
    >
    >
    > "Peter" <> wrote in message
    > news:bkr1ib$...
    > > Hi,
    > >
    > > I was wondering how do you compare variables that contain text strings

    in
    > > ASP.
    > >
    > > When I use the following If.. Then statement:
    > >
    > > If Rs("StyleNo") <> arrStyleNo(aCount) Then
    > >
    > >
    > > I always get the following error when I try to browse the page:
    > >
    > > Error Type:
    > > (0x80020009)
    > > Exception occurred.
    > >
    > >
    > > Thanks.
    > >
    > > Peter
    > >
    > >

    >
    >
     
    Peter, Sep 26, 2003
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. ech0

    Insert text contain code

    ech0, Mar 27, 2005, in forum: ASP .Net
    Replies:
    6
    Views:
    543
    Kikoz
    Mar 29, 2005
  2. Alan Johnson
    Replies:
    0
    Views:
    408
    Alan Johnson
    Jul 24, 2007
  3. Replies:
    9
    Views:
    1,013
  4. Roger Pack
    Replies:
    3
    Views:
    184
    Roger Pack
    Sep 28, 2010
  5. Jason Carlton
    Replies:
    11
    Views:
    265
    Dr J R Stockton
    Dec 8, 2009
Loading...

Share This Page