By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,454 Members | 2,629 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,454 IT Pros & Developers. It's quick & easy.

compare variables that contain text

P: n/a
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
Jul 19 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
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" <pe***@visors.com.hk> wrote in message
news:bk*********@imsp212.netvigator.com...
: 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
:
:
Jul 19 '05 #2

P: n/a
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" <pe***@visors.com.hk> wrote in message
news:bk*********@imsp212.netvigator.com...
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

Jul 19 '05 #3

P: n/a
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> bl
news:%2****************@TK2MSFTNGP09.phx.gbl 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" <pe***@visors.com.hk> wrote in message
news:bk*********@imsp212.netvigator.com...
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


Jul 19 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.