I need to identify the real number in a string which is actually a file

name. Here are a few examples:

R55567E1-A-1.TXT I need 55567

R442A-B-2.TXT I need 442

R11258974-A-1.TXT I need 1125897

The constant in all the file names are that the real number I need

follows the R. Can I evaluate, beginning with the 2nd position, and

read until no real number is found?

Thanks,

Bill

Bill

A bit of air code

Dim RealNumber as long

...

RealNumber = Clng(Mid$(filename,2))

Richard

Web pages: http://www.yqcomputer.com/ ,

http://www.yqcomputer.com/ ://www.homeindorset.co.uk

because I loves the domain name for email.

--

You know, I used to think I was stupid, and then I met philosophers. - 'Small

Gods' by Terry Pratchett

>I need to identify the real number in a string which is actually a file

You didn't say whether you wanted the number to be a String value or a

numerical value... I assumed numerical. Here is some code for you to look

at...

Dim X As Long

Dim FName As String

Dim Number As Long

FName = "R55567E1-A-1.TXT"

For X = 2 To InStr(FName, ".")

If Not Mid$(FName, X, 1) Like "#" Then

Number = CLng(Mid$(FName, 2, X - 2))

Exit For

End If

Next

Rick

You didn't say whether you wanted the number to be a String value or a

numerical value... I assumed numerical. Here is some code for you to look

at...

Dim X As Long

Dim FName As String

Dim Number As Long

FName = "R55567E1-A-1.TXT"

For X = 2 To InStr(FName, ".")

If Not Mid$(FName, X, 1) Like "#" Then

Number = CLng(Mid$(FName, 2, X - 2))

Exit For

End If

Next

Rick

As you describe things, the function below will return what you want.

Ivar

Private Function GetRealNum(FileName As String) As String

Dim I As Integer

Dim S As String

For I = 2 To Len(FileName)

If IsNumeric(Mid(FileName, I, 1)) Then

S = S & Mid(FileName, I, 1)

Else:

Exit For

End If

Next

GetRealNum = S

End Function

Ivar

Private Function GetRealNum(FileName As String) As String

Dim I As Integer

Dim S As String

For I = 2 To Len(FileName)

If IsNumeric(Mid(FileName, I, 1)) Then

S = S & Mid(FileName, I, 1)

Else:

Exit For

End If

Next

GetRealNum = S

End Function

That would be it. I would do something like this aircode:

GetFileNumber([filename])

Function GetFileNumber(strFileName as String)

For x = 2 to Len(strFileName)

If isnumeric(mid(strFileName,x,1) Then

GetFileNumber = GetFileNumber & mid(strFileName,x,1)

Else

Exit For

End If

Next

End Function

GetFileNumber([filename])

Function GetFileNumber(strFileName as String)

For x = 2 to Len(strFileName)

If isnumeric(mid(strFileName,x,1) Then

GetFileNumber = GetFileNumber & mid(strFileName,x,1)

Else

Exit For

End If

Next

End Function

>>I need to identify the real number in a string which is actually a file

CLng won't work, but I believe you were thinking of Val instead.

Unfortunately, that won't work either. Actually, it works, but the type of

String values makes it possible for Val to return an incorrect value. Using

the first filename as an example...

RealNumber = Val(Mid$(filename, 2)

will assign 555670 and not the correct value of 55567 to the RealNumber

variable. Why? Well, it is because the E1 after the actual number is

properly a power of ten designation and Val respects that. The number Val

sees is 55567E1.

Rick

CLng won't work, but I believe you were thinking of Val instead.

Unfortunately, that won't work either. Actually, it works, but the type of

String values makes it possible for Val to return an incorrect value. Using

the first filename as an example...

RealNumber = Val(Mid$(filename, 2)

will assign 555670 and not the correct value of 55567 to the RealNumber

variable. Why? Well, it is because the E1 after the actual number is

properly a power of ten designation and Val respects that. The number Val

sees is 55567E1.

Rick

On Fri, 5 May 2006 15:27:54 -0400, "Rick Rothstein"

Rick

I did say it was air-code. I agree that your response to Bill should be the

way he should go.

Richard

Web pages: http://www.yqcomputer.com/ ,

http://www.yqcomputer.com/ ://www.homeindorset.co.uk

because I loves the domain name for email.

--

You know, I used to think I was stupid, and then I met philosophers. - 'Small

Gods' by Terry Pratchett

Rick

I did say it was air-code. I agree that your response to Bill should be the

way he should go.

Richard

Web pages: http://www.yqcomputer.com/ ,

http://www.yqcomputer.com/ ://www.homeindorset.co.uk

because I loves the domain name for email.

--

You know, I used to think I was stupid, and then I met philosophers. - 'Small

Gods' by Terry Pratchett

I would write a totally generic routine that can be used in any App :-

Private Sub Command1_Click()

Me.Print ExtractFirstNumber("R55567E1-A-1.TXT")

Me.Print ExtractFirstNumber("R442A-B-2.TXT")

Me.Print ExtractFirstNumber("R11258974-A-1.TXT")

End Sub

Private Function ExtractFirstNumber&(ByVal S$)

Dim L9&, DoneFlag As Boolean

Dim C As String * 1

For L9 = 1 To Len(S$) + 1 ' force last

C = Mid$(S$, L9, 1)

If InStr("0123456789", C$) = 0 Then

Select Case DoneFlag

' --- it is a leading non-numeric

Case False: Mid$(S$, L9, 1) = " "

DoneFlag = True

' --- it is a trailing non-numeric

Case True:

If L9 <= Len(S$) Then

Mid$(S$, L9, 1) = "X"

End If

ExtractFirstNumber = Val(S$)

Exit For

End Select

End If

Next

End Function

In fact, I would make it even more generic :-

Private Sub Command2_Click()

Dim A$(3), L9&

A$(1) = "R55567E1-A-1.TXT"

A$(2) = "R442A-B-2.TXT"

A$(3) = "R11258974-A-1.TXT"

For L9 = 1 To 3

Me.Print A$(L9); " ";

Me.Print ExtractNthNumber(A$(L9), 1)

Next

Me.Print

For L9 = 1 To 3

Me.Print A$(L9); " ";

Me.Print ExtractNthNumber(A$(L9), 2)

Next

Me.Print

For L9 = 1 To 3

A$(L9) = A$(L9) + "123"

Me.Print A$(L9); " ";

Me.Print ExtractNthNumber(A$(L9), 3)

Next

End Sub

Private Function ExtractNthNumber&(S$, Nth&)

Dim L9&, Count&, Start&

Dim LastNumericFlag As Boolean

Dim C As String * 1

' --- Find start of Nth Number

For L9 = 1 To Len(S$)

C = Mid$(S$, L9, 1)

Select Case (InStr("0123456789", C$) > 0)

' --- Numeric

Case True:

If LastNumericFlag = False Then

Count = Count + 1

If Count = Nth Then

Start = L9

Exit For

End If

End If

LastNumericFlag = True

' --- Not Numeric

Case False:

LastNumericFlag = False

End Select

Next

' --- Failed

If Start = 0 Then

Exit Function

End If

Count = 1

For L9 = Start To Len(S$) + 1 ' force last

C = Mid$(S$, L9, 1)

If InStr("0123456789", C$) = 0 Then

ExtractNthNumber = Val(Mid$(S$, Start, Count))

Exit For

End If

Count = Count + 1

Next

End Function

1. how to identify identify a wrong number

2. Detailsview shows real numbers with commata: Error converting data type nvarchar to real!

3. Mac Net Apps share trend analyzed with real numbers and real statistics!

4. Returning the real numbers withing a vector containing imaginary and real

5. Identify number of numeric sets in a long string of numbers

6. How do I identify different numbers to a table of numbers

7. identify even numbers with a "1" and odd numbers with a "0"

8. Complex Numbers to Real numbers

9. change from real numbers to complex numbers

10. convert string number to real number - ValueError: invalid literal for int() with base 10: '"2"'

11. Converting String numbers into real numbers

12. "A random real number will be on a computables list to an infinite number of digits"

13. New real number handling using some feedback from studying complex numbers

14. real number to 16 bit signed number

15. "A random real number will be on a computables list to an infinite number of digits"

8 post • Page:**1** of **1**