Web Wiz - Green Windows Web Hosting

  New Posts New Posts RSS Feed - Comparing Numeric Values
  FAQ FAQ  Forum Search   Events   Register Register  Login Login

Comparing Numeric Values

 Post Reply Post Reply Page  123>
Author
Misty View Drop Down
Senior Member
Senior Member
Avatar

Joined: 06 February 2002
Location: United States
Status: Offline
Points: 711
Post Options Post Options   Thanks (0) Thanks(0)   Quote Misty Quote  Post ReplyReply Direct Link To This Post Topic: Comparing Numeric Values
    Posted: 05 October 2004 at 2:06pm

I have a desire to be able to find out if a certain number (AreaID) exists in a database or not. If the areaID exists in the database, I don't want any updates to the database. Please look at the bolded line below. Both Area and rsCity("Area") are numbers. I know how to do this with letters, but I am not sure how to do with numbers. With letters, you would do something like: If Lcase(City) = Lcase(rs2("City")) Then

Here's some of the code:
'Initalize Error
Error = False
'Loop through all the records in the recordset to check that the areaID is not already in the database
Do While NOT rsCity.EOF
'Check to see if the database already has this area
If Area = rsCity("AreaID") Then
Error = True %>

Back to Top
Gullanian View Drop Down
Senior Member
Senior Member
Avatar

Joined: 04 January 2002
Location: England
Status: Offline
Points: 4373
Post Options Post Options   Thanks (0) Thanks(0)   Quote Gullanian Quote  Post ReplyReply Direct Link To This Post Posted: 05 October 2004 at 2:29pm
If Area ID isn't a numeric datatype, change it to:

cLng(rsCity("areaID"))

And change Area to:

clng(area)

So it might read:

cLng(Area) = cLng(rsCity("AreaID"))
Back to Top
Gullanian View Drop Down
Senior Member
Senior Member
Avatar

Joined: 04 January 2002
Location: England
Status: Offline
Points: 4373
Post Options Post Options   Thanks (0) Thanks(0)   Quote Gullanian Quote  Post ReplyReply Direct Link To This Post Posted: 05 October 2004 at 2:31pm
PS:  An explanation of cLng()

cLng() converts the passed value into a long integer.  You also have cInt() which convers the passed value into an integer.  If either of the two things you are comparing are not numerical, but string, then you can't compare them until they are both integers.
Back to Top
Misty View Drop Down
Senior Member
Senior Member
Avatar

Joined: 06 February 2002
Location: United States
Status: Offline
Points: 711
Post Options Post Options   Thanks (0) Thanks(0)   Quote Misty Quote  Post ReplyReply Direct Link To This Post Posted: 05 October 2004 at 2:48pm

Gullanian,

Thank you for the information!

Both are int in datatype in my SQL Server database. Which cInt or cLng would be best for this case? I am just not sure because my database will only allow up to 4 numbers for the AreaID.

Back to Top
theSCIENTIST View Drop Down
Senior Member
Senior Member


Joined: 31 July 2003
Location: United Kingdom
Status: Offline
Points: 440
Post Options Post Options   Thanks (0) Thanks(0)   Quote theSCIENTIST Quote  Post ReplyReply Direct Link To This Post Posted: 05 October 2004 at 3:29pm
Originally posted by Misty Misty wrote:

Error = False
Do While NOT rsCity.EOF
If Area = rsCity("AreaID") Then
Error = True %>

Just spotted something that is unrelated to your query, but that can be improved. I don't know the rest of the code, but I'm assuming you are going through the recordset to determine if AreaID exists or not, and if it does Error becomes true, why not exiting the Do ... Loop you are in by using a Exit Do? If you don't, the recordset will continue to be probed even thou your condition has been met, wasting cycles and all.

Error = False

Do While NOT rsCity.EOF
If Area = rsCity("AreaID") Then
Error = True
Exit Do %>

Just a point.
Back to Top
Misty View Drop Down
Senior Member
Senior Member
Avatar

Joined: 06 February 2002
Location: United States
Status: Offline
Points: 711
Post Options Post Options   Thanks (0) Thanks(0)   Quote Misty Quote  Post ReplyReply Direct Link To This Post Posted: 05 October 2004 at 3:47pm

theScientist,

Thank you for noticing! I already had Exit Do in my code. I just chose to not post all of the code because I was focused on that one line.

Back to Top
Misty View Drop Down
Senior Member
Senior Member
Avatar

Joined: 06 February 2002
Location: United States
Status: Offline
Points: 711
Post Options Post Options   Thanks (0) Thanks(0)   Quote Misty Quote  Post ReplyReply Direct Link To This Post Posted: 05 October 2004 at 4:11pm

I cannot get the query to work. I am getting the following error message:

Either BOF or EOF is True, or the current record has been deleted. Requested operation requires a current record.

Can someone please help me to figure out what is wrong? The querystring is right. I suspect that it might have to do something with the comparison of the integers.

Let me show more code:

  'Create a recordset

      set rsCity = Server.CreateObject("ADODB.Recordset")

      rsCity.Open sql, connectionString, adOpenDynamic, adLockOptimistic

     

    'Initalize Error

    Error = False

   

    'Loop through all the records in the recordset to check that the user id and the e-mail address are not already in the database

                         Do While NOT rsCity.EOF

   

    'Check to see if the database already has this city

    If cLng(Area) = cLng(rsCity("AreaID")) then

   

 

   

    Error = True

   

    

    %>

 

<%

 

 

Exit Do

End If                  

 

'Move to the next recordset

rsCity.MoveNext

Loop

 

 

If Error = False then 

 

      

      rsCity("AreaID") = Area (this is the line that the error message is on)

 

     

      rsCity.update

Back to Top
theSCIENTIST View Drop Down
Senior Member
Senior Member


Joined: 31 July 2003
Location: United Kingdom
Status: Offline
Points: 440
Post Options Post Options   Thanks (0) Thanks(0)   Quote theSCIENTIST Quote  Post ReplyReply Direct Link To This Post Posted: 05 October 2004 at 4:23pm
The problem is because you are updating if AreaID doesn't exist, how can you then go on and update it if it doesn't exist?

I'm also a bit confused, what number is that you look for? A value in a field? Or is it the field itself?
Back to Top
 Post Reply Post Reply Page  123>

Forum Jump Forum Permissions View Drop Down

Forum Software by Web Wiz Forums® version 12.08
Copyright ©2001-2026 Web Wiz Ltd.


Become a Fan on Facebook Follow us on X Connect with us on LinkedIn Web Wiz Blogs
About Web Wiz | Contact Web Wiz | Terms & Conditions | Cookies | Privacy Notice

Web Wiz is the trading name of Web Wiz Ltd. Company registration No. 05977755. Registered in England and Wales.
Registered office: Web Wiz Ltd, Unit 18, The Glenmore Centre, Fancy Road, Poole, Dorset, BH12 4FB, UK.

Prices exclude VAT at 20% unless otherwise stated. VAT No. GB988999105 - $, € prices shown as a guideline only.

Copyright ©2001-2026 Web Wiz Ltd. All rights reserved.