Seperating numbers and characters

G

Guest

using vb in access 2003 i return a value which is made up of numbers and a
letter.

for example "305L"

i need to seperate the numbers and letter

i can use the right function to return the character from the right hand
side but how do i return just the numbers? The numbers can consist of 3 or 4
digits.

any help would be appreciated.
 
D

Douglas J. Steele

Assuming that it always starts with the numbers, use the Val function.

Val("305L") will return 305.
 
G

Guest

Douglas' solution is the easiest, provided the number part is alway the first
part of the string. If not, this should work for you (after you debug it.
It is untested air code)

Function GetNumsOnly(strOriginal) as String
Dim intCtr as Integer
Dim strResult as String
Const conNums As String = "0123456789"

For intCtr = 1 To Len strOriginal
If Instr(conNums, Mid(strOriginal, intCtr, 1)) <> 0 Then
strResult = strResult & Mid(strOriginal, intCtr)
End If
Next intCtr

GetNumsOnly = strResult

End Function
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Excel Convert word into numbers and back 4
Custom validation rule 4
Counting Numbers 26
Seperating a variable length string 5
complex code 8
Split data in field on character return 0
Character Count 3
Validating data 1

Top