Left/Right/Mid

prasadgov

Member
Local time
Today, 10:37
Joined
Oct 12, 2021
Messages
135
TIA,

How to get just the value, 50000000 from /FAMT/50000000,
 
Use InstrRev() and Right()
Or you could use Split() but that would involve several lines of code.
 
Last edited:
Code:
mid(x, InStrRev(x, "/") + 1)
 
We'd need more examples to make a valid general algorithm. Is it always after the 2nd slash? Could there be extra characters after it?
 
If there is a format rule for that field such that the number you want is ALWAYS last, then MajP's suggestion is probably easiest and most direct. If there are variations to consider, we would need to know them all.
 
We'd need more examples to make a valid general algorithm. Is it always after the 2nd slash? Could there be extra characters after it?
No extra characters after that. That is how the data comes in always.
 
Wouldn't Val return the correct value? Not sure if the slashes would interfere.
 
Wouldn't Val return the correct value? Not sure if the slashes would interfere.

'Fraid not, Dave. "The Val function stops reading the string at the first character that it can't recognize as part of a number."


I think that if it is always \xxxx\number then the InStrRev suggestion from MajP is best.
 
If the prefix is always "/FAMT/" then use...
Code:
Mid([fieldname], 7)
 
you can also use RegExp:
Code:
' chatgpt
Function ExtractNumbers(inputString As String) As String
    Dim regex As Object
    Set regex = CreateObject("VBScript.RegExp")
    
    Dim matches As Object
    Dim match As Object
    Dim result As String
    
    ' Regular expression pattern to match numbers (including decimals)
    regex.Pattern = "\b\d+(\.\d+)?\b"
    regex.Global = True
    regex.IgnoreCase = True
    
    ' Check if there are matches
    If regex.Test(inputString) Then
        ' Get all matches
        Set matches = regex.Execute(inputString)
        
        ' Build the result string from matches
        For Each match In matches
            result = result & match.Value & " "
        Next match
        
        ' Remove trailing space
        result = Trim(result)
    End If
    
    ExtractNumbers = result
End Function

?ExtractNumbers("/FAMT/50000000,")
result: 50000000
 

Users who are viewing this thread

Back
Top Bottom