Web Wiz - Green Windows Web Hosting

  New Posts New Posts RSS Feed - Find if field contains number
  FAQ FAQ  Forum Search   Events   Register Register  Login Login

Find if field contains number

 Post Reply Post Reply
Author
pedalcars View Drop Down
Senior Member
Senior Member


Joined: 12 August 2002
Location: United Kingdom
Status: Offline
Points: 268
Post Options Post Options   Thanks (0) Thanks(0)   Quote pedalcars Quote  Post ReplyReply Direct Link To This Post Topic: Find if field contains number
    Posted: 29 July 2003 at 2:54am
Hope this makes sense...

I have a table with a field containing a collection of numbers, each separated by a controlled character (which could be anything, like a space, comma, dash, underscore, colon, etc.), so for example one record could be:

1,2,9,13,7,4

This string will be assigned to a variable, I then want to compare this to another, single number, such that if the single number is contained within the first string, the record is displayed, otherwise it is ignored, eg:

strLotsOfNumbers = 1,2,9,13,7,4

If strLotsOfNumbers (contains) rs("SingleNumber") Then (display rs("FieldName"))


However, it also has to compare the entire number between separators, so in the example above if rs("SingleNumber") = 3 it would return FALSE, ie, wouldn't match the '3' with the second character of the '13'.

If necessary I can start, end, or both, the long string with the control character, like: ,1,2,9,13,7,4, so each number is surrounded.

Thanks in anticipation

Edited by pedalcars
www.pedalcars.info

The most fun on four wheels

Back to Top
b_bonnett View Drop Down
Mod Builder Group
Mod Builder Group


Joined: 16 April 2003
Location: New Zealand
Status: Offline
Points: 275
Post Options Post Options   Thanks (0) Thanks(0)   Quote b_bonnett Quote  Post ReplyReply Direct Link To This Post Posted: 29 July 2003 at 3:11am

My guess would be to surround strLotsOfNumbers in the control character, set strControl = "," (or whatever), then use:

If InStr(strLotsOfNumbers, strControl & intNumberToCompare & strControl) Then...

Thats just a guess - haven't tested it but think it should work.

Blair

Webmaster, The Plane Gallery
Greetings From Christchurch
Back to Top
Flamewave View Drop Down
Senior Member
Senior Member
Avatar

Joined: 19 June 2002
Location: United States
Status: Offline
Points: 376
Post Options Post Options   Thanks (0) Thanks(0)   Quote Flamewave Quote  Post ReplyReply Direct Link To This Post Posted: 29 July 2003 at 10:16am

Another way of doing it would be to split up the number list into an array and then use a for loop to compare the numbers. This method requires a bit more code then the method bonnett mentioned, but at least this way you wouldn't be dependant upon comparing strings, which can get messy if you get extra characters in there, such as if you end up with a space between commas, then the method above would not work unless you specifically checked for that.

temparray = split(strLotsOfNumbers, ",")
For loopcounter = 0 to Ubound(temparray)
    If Int(temparray(loopcounter)) = intNumberToCompare Then
        ...
        Exit For
    End If
Next

- Flamewave

They say the grass is greener on the other side, but if you really think about it, the grass is greener on both sides.
Back to Top
ljamal View Drop Down
Mod Builder Group
Mod Builder Group


Joined: 16 April 2003
Status: Offline
Points: 888
Post Options Post Options   Thanks (0) Thanks(0)   Quote ljamal Quote  Post ReplyReply Direct Link To This Post Posted: 29 July 2003 at 11:18am
Use the inStr Method it's more efficient with longer string as you will not be looping through the an unknown number of values.
Back to Top
 Post Reply Post Reply

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.