Confused....

1. Senior Member
Join Date
Dec 1969
Posts
106

## Confused....

This is throwing me for a "loop":<BR><BR>Why would this work, meaning output a value of oRs("age"):<BR>For i=1 to 70<BR>If i=25 Then <BR>Response.write oRs("age")<BR>END IF<BR>Next<BR><BR>....and this not work:<BR><BR>For i=1 to 70<BR>If i=oRs("age") Then<BR>Response.write oRs("age")<BR>END IF<BR>Next<BR><BR>The difference is i=25 or i=oRs("age"). I have confirmed that oRs("age") has a numeric value all the way to this line of code.<BR><BR><BR>

2. Senior Member
Join Date
Dec 1969
Posts
96,118

## What is the data type...

...of the "age" field in that table? Look at your DB schema to be sure. Don&#039;t assume.<BR><BR>And did you try something simple such as:<BR><BR>For i=1 to 70<BR> If i = [hl="yellow"]CLNG(oRs("age"))[/hl] Then<BR> Response.write oRs("age")<BR> END IF<BR>Next<BR><BR>???<BR>

3. Senior Member
Join Date
Dec 1969
Posts
1,843

## RE: Confused....

1) You&#039;re sure that oRs("age") is equal to 25? <BR><BR>2) Even though you say you know the datatype, just for kicks try: <BR><BR>If cDbl(i) = cDbl(oRs("age")) Then<BR>

4. Senior Member
Join Date
Dec 1969
Posts
1,843

## 2 seconds... you must have a faster connection

.

5. Senior Member
Join Date
Dec 1969
Posts
96,118

## Interesting...

Why use the CDBL???<BR><BR>If oRs("age") is really 25.312817, then it&#039;s never going to be equal to 25, anyway.<BR><BR>And the variable "i" is already guaranteed to be an integer, which is automatically converted to double if need be.<BR><BR>Hmmm...<BR><BR>I think I like <BR><BR> If i = cDbl(oRs("age")) Then<BR><BR>It means that you will *not* get a match on 25.3434381 if there happens to be one in the table. Doing CDBL(i) isn&#039;t necessary, but it sure doesn&#039;t hurt anything.<BR><BR>Of course, if you are *expecting* the values in the DB to always be integers, then I&#039;d stick with my CLNG, but still...<BR><BR>Fun.<BR><BR>

6. Senior Member
Join Date
Dec 1969
Posts
1,843

## RE: Interesting...

Honestly, I did it because I was flamed before for using cInt (even though he&#039;s doing a loop and I HOPE it&#039;s not looping tens of thousands of times) and cdbl has always been a safe bet for me :)

7. Senior Member
Join Date
Dec 1969
Posts
106

## CLNG....

well this did the trick, If i=CLNG(oRs("age")) Then...<BR><BR>FYI, the db data type is &#039;number&#039;<BR><BR>Thanks for the info!<BR><BR><BR><BR>

8. Senior Member
Join Date
Dec 1969
Posts
96,118

## That explains it...

VBScript doesn&#039;t automatically convert the DB type "number" into an integer, so you have to "nudge" it along.<BR><BR>

9. Senior Member
Join Date
Dec 1969
Posts
96,118

## Agreed...

CDBL is pretty much guaranteed to work, if the data can at all be translated into any numeric form that VBS understands.<BR><BR>Better safe than sorry.<BR><BR>

10. Senior Member
Join Date
Dec 1969
Posts
96,118

## Naw...

...I just type faster. &#060;grin /&#062;<BR><BR>

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•