2

I'm trying to automate a script using QTP and SAP.

In SAP an order is generated with Document number in status bar as "Standard PO created under the number 4500290636"

My challenge is how should I convert take string to an Integer value.

1
  • Does your numeric string always occur at the end, is it always 10 digita? Commented Oct 13, 2012 at 10:50

3 Answers 3

1

Since you are using SAP, I think it is safe to assume that the document number will always have a length of 10 characters. So, you can extract it using the Right function, then just convert it using Val. Something like this:

yourInteger = Val(Right(yourSAPString, 10))

Note: in .net, you could use Convert.ToInt32 instead of Val

Sign up to request clarification or add additional context in comments.

Comments

1

You could use the split function:

Dim strSplit As Variant
Dim yourNumericOut As Variant

    strSplit = Split("Standard PO created under the number 4500290636")

    If IsNumeric(UBound(strSplit)) Then yourNumericOut = --strSplit(UBound(strSplit))

Then test for numeric, will allow for many lengths and could change the position of the number in the returned values.

Comments

0

I would recommend using a custom function.

Here is the function:

Public Function ExtractNumber(fromString As String) As Double
    Dim RegEx As Object
    Set RegEx = CreateObject("VBScript.RegExp")
    With RegEx
        .Pattern = "(\d{1,3},?)+(\.\d{2})?"
        .Global = True
        If .Test(fromString) Then
            ExtractNumber = CDbl(.Execute(fromString)(0))
        End If
    End With
End Function

Here is the usage example:

Sub Example()
    Debug.Print ExtractNumber("Standard PO created under the number 4500290636")
End Sub

This code was taken from a similar, more recent answer that has better solutions. See here: Excel VBA - Extract numeric value in string

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.