+ Reply to Thread
Results 1 to 3 of 3

Extract based on Delimiters

  1. #1
    ssjody
    Guest

    Extract based on Delimiters

    On a Form I have a Combo Box that lists values like this
    1.2.3.4
    10.11.12.13
    90.121.92.93
    where the "." periods are my delimiter

    I want to extract only the 1st two octets and write them to a
    worksheet.

    What code could I use to extract based on a delimiter? For example if I
    pick the 1st example in my list, the 1.2 would be extracted and set as
    the value to write to my worksheet. If the 2nd example was chosen,
    10.11 would be written.

    Any Ideas?

    Jody


  2. #2
    Jim Cone
    Guest

    Re: Extract based on Delimiters

    Jody,
    Here is an idea...

    '---------------------------------
    Function FirstTwoSections(ByRef strInput As String)
    'Returns the portion of a provided string that occurs before the
    'second dot. If only one dot then entire string is returned.
    'Jim Cone - San Francisco - USA - 12/26/2005.
    Dim strResult As String
    Dim lngLength As Long
    Dim lngN As Long

    lngLength = 0
    For lngN = 1 To 2
    lngLength = InStr(lngLength + 1, strInput, ".", vbTextCompare)
    Next
    If lngLength > 0 Then
    strResult = Left$(strInput, lngLength - 1)
    Else
    lngLength = InStr(1, strInput, ".", vbTextCompare)
    If lngLength > 0 Then
    strResult = strInput
    Else
    strResult = "No dots "
    End If
    End If
    FirstTwoSections = strResult
    End Function


    'Calls Function
    Sub GetNumber()
    Dim strFromCombo As String
    strFromCombo = "1.22.333.444"
    Msgbox FirstTwoSections(strFromCombo)
    End Sub

    '----------------
    Jim Cone
    San Francisco, USA
    http://www.realezsites.com/bus/primitivesoftware




    "ssjody" <[email protected]> wrote in message
    news:[email protected]
    On a Form I have a Combo Box that lists values like this
    1.2.3.4
    10.11.12.13
    90.121.92.93
    where the "." periods are my delimiter

    I want to extract only the 1st two octets and write them to a
    worksheet.
    What code could I use to extract based on a delimiter? For example if I
    pick the 1st example in my list, the 1.2 would be extracted and set as
    the value to write to my worksheet. If the 2nd example was chosen,
    10.11 would be written.
    Any Ideas?
    Jody


  3. #3
    Bob Phillips
    Guest

    Re: Extract based on Delimiters

    Try this

    sTest = "10.11.12.13"

    Debug.Print Left(sTest, InStr(InStr(sTest, ".") + 1, sTest, ".") - 1)


    --

    HTH

    RP
    (remove nothere from the email address if mailing direct)


    "ssjody" <[email protected]> wrote in message
    news:[email protected]...
    > On a Form I have a Combo Box that lists values like this
    > 1.2.3.4
    > 10.11.12.13
    > 90.121.92.93
    > where the "." periods are my delimiter
    >
    > I want to extract only the 1st two octets and write them to a
    > worksheet.
    >
    > What code could I use to extract based on a delimiter? For example if I
    > pick the 1st example in my list, the 1.2 would be extracted and set as
    > the value to write to my worksheet. If the 2nd example was chosen,
    > 10.11 would be written.
    >
    > Any Ideas?
    >
    > Jody
    >




+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1