Web Wiz - Green Windows Web Hosting

  New Posts New Posts RSS Feed - From a String to an Integer
  FAQ FAQ  Forum Search   Events   Register Register  Login Login

From a String to an Integer

 Post Reply Post Reply
Author
themadjuggler View Drop Down
Newbie
Newbie
Avatar

Joined: 16 May 2003
Status: Offline
Points: 2
Post Options Post Options   Thanks (0) Thanks(0)   Quote themadjuggler Quote  Post ReplyReply Direct Link To This Post Topic: From a String to an Integer
    Posted: 16 May 2003 at 5:16pm

Hi there,

Begin here for the long story.

     While I use databases, much of the content of my site is stored in text files (named 1.txt, 2.txt, 3.txt etc.). These numbers correspond to the primary key of one of my Acess database tables which serves as a sort of index for these.

     Anyway, I'm making a search engine for the site, and while I can identify which text files include the search string, I can't make the correlation between the text file and the appropriate record in my database.

     I have been able to take the text file name and shorten it to simply the number, leaving me with a string that contains a number in it.

Begin here for the short story

     I need to SELECT a number of fields from a table in records WHERE the primary key is equal to a specific number. The problem is, this number is contained in a string, not an integer. How should I go about changing its data type, considering I'm using ASP and VBScript?

What I've tried

      I tried to be tricky and convert each digit of the number (first checking to see how many digits it was) with the asc() command, then subtracting 48 from that result (the number 0-9 in ASCII being 48-57). Still, this yields the data type mismatch error. Should I just switch languages for this page? Anyway, here's some convoluted code:

'Determine the number of digits in the ListID

'Then convert to ASCII, adjust to actual number... JESUS CHRIST!

if len(fileNumString) = 1 then

fileNumNumber = asc(fileNumString) - 48

end if

if len(fileNumString) = 2 then

tempIntOnes = Right(fileNumString, 1)

tempIntOnes = asc(tempIntOnes) - 48

tempIntTens = asc(fileNumString) - 48

fileNumNumber = (tempIntTens * 10) + tempIntOnes

end if

if len(fileNumString) = 3 then

tempIntOnes = Right(fileNumString, 1)

tempIntOnes = asc(tempIntOnes) - 48

tempIntTens = Mid(fileNumString, 1, 1)

tempIntTens = asc(tempIntTens) - 48

tempIntHuns = asc(fileNumString) - 48

fileNumNumber = (tempIntHuns * 100) + (tempIntTens * 10) + tempIntOnes

end if

sSQL = "SELECT ListID, ListAuthor, ListTitle, ListDescription FROM Playlists WHERE ListID = '" & fileNumNumber & "'"

 

Thanks for any help you can give :-)

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

Joined: 08 April 2002
Location: United States
Status: Offline
Points: 4670
Post Options Post Options   Thanks (0) Thanks(0)   Quote michael Quote  Post ReplyReply Direct Link To This Post Posted: 16 May 2003 at 6:14pm
If I understand you right you are going through way too much trouble. You can generally use something like CInt(string)
thus in the databse loose the single quotes so it should not matter at all: sSQL = "SELECT ListID, ListAuthor, ListTitle, ListDescription FROM Playlists WHERE ListID = " & string   'String being a number
Back to Top
themadjuggler View Drop Down
Newbie
Newbie
Avatar

Joined: 16 May 2003
Status: Offline
Points: 2
Post Options Post Options   Thanks (0) Thanks(0)   Quote themadjuggler Quote  Post ReplyReply Direct Link To This Post Posted: 16 May 2003 at 6:25pm

That worked with my first try at the cInt function. A million thanks, this has really been irking me!

(heh, and I thought my plan was so devious :)

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: 16 May 2003 at 11:49pm
If you are working with large number ooutside the range of the integer datatype you may wish to use CLng rather than CInt. I think the max for integer datatype is around 32,000.
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.