Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations MikeeOK on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Convert Character Field Value to Integer

Status
Not open for further replies.

EdAROC

Programmer
Aug 27, 2002
93
US
I have to parse a character field and convert the result to an integer. Help.

So far I have been able to parse the field and end up with a character string of the numeric characters. Ex: Z12345-1--1 is parsed to 12345.

FYI - Once I do this I will use this query to link to a table where the primary key is the parsed value (int).
 
Maybe this bit of information needs to be added:
Not every record will contain a value, a value is always of the format Z12345-1--. If there is no ITEM_NO the field is Null (I checked).

Here is my latest expression:
SPEC_NO: IIf([ITEM_NO] Is Null, Null, CInt(Replace(Left([ITEM_NO], InStr([ITEM_NO], "-")-1), "Z", "")))

The records with a value show "#Error". The Null fields remain Null.

When I have: Replace(Left([ITEM_NO], InStr([ITEM_NO], "-")-1), "Z", "")) the values show OK - it's just they are a character string.
Hmmm.
 
Strange...I just added ran a test, using the same expression you posted (with the CInt), and it worked fine. Are you sure you have it exactly as you posted?
 
Replace CInt( with Val(

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Val(...) worked - the values are displaying right justified.

Thanks.

BTW - rjoubert I copied/pasted to make sure you got what I was using.

Went to my "cheat sheet website for functions" -
and looked up Val(...). That's what I needed.

What does CInt actually do. Above website states it returns the Integer of a value (does "value" mean numeric or alphanumeric?) [.5 rounds down!!!].

Thanks again!! Really helps me with this project I'm working on.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top