Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   ASP General (http://www.velocityreviews.com/forums/f65-asp-general.html)
-   -   compare variables that contain text (http://www.velocityreviews.com/forums/t790440-compare-variables-that-contain-text.html)

Peter 09-24-2003 03:01 AM

compare variables that contain text
 
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 09-24-2003 03:12 AM

Re: compare variables that contain text
 
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" <peter@visors.com.hk> wrote in message
news:bkr1ib$rjp2@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
:
:



Curt_C [MVP] 09-24-2003 03:16 AM

Re: compare variables that contain text
 
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" <peter@visors.com.hk> wrote in message
news:bkr1ib$rjp2@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
>
>




Peter 09-26-2003 01:57 AM

Re: compare variables that contain text
 
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:%23LI5bokgDHA.2248@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" <peter@visors.com.hk> wrote in message
> news:bkr1ib$rjp2@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
> >
> >

>
>





All times are GMT. The time now is 02:03 PM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.