CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    May 2010
    Posts
    1

    ectract text from line (VBA+ACCESS)

    Hello,

    I have problem with extracting text form line.

    Source text look like this:

    PC - IBM
    Title: order
    Description: normal Car Repair AS, reg. 10343234 101
    Car Repair , Wall Street, New York 43434

    I need to, extract data from those fields. I cannot do it with Length, in every case is the data different. Invariable (data that do not change) are "Title:", "Description:", "reg." and spaces.

    I managed to extract the invariable "reg." 8 charters after text "reg."

    'Search and extract reg.
    strSearch = "reg. "
    intWhere = InStr(.Value, strSearch)
    If intWhere Then
    .SetFocus
    .SelStart = intWhere + 4
    .SelLength = 8
    '.SelLength = Len(strSearch)
    TReg.Value = .SelText
    End If

    But I can`t figure out how to extract Company name, in this case - Car Repair AS. I assume that it can be done with space. Display data between "second space" and ","

    Can anyone help me on this one ? Thank you

    My apologies for my poor writing skills.

  2. #2
    Join Date
    Jul 2008
    Location
    WV
    Posts
    5,362

    Re: ectract text from line (VBA+ACCESS)

    Since you only gave us one instance there is not much of a way to tell what is static and what is variable. I assume that Description: is static I do not know about " normal "

    You should look at Split() however as it can at least get you started here.

    for example If you use Split on the description line using the comma it will give you 2 strings [the ones on each side of the comma] If you use split again on the first of those strings this time using the : it will give you 2 strings one being Description and the other being what follows it up to the comma. The second string [from the first split] if you used split and . you would get reg in one string and the number in the other.

    Play with that a bit and you should be able to get the results you are after.


    ETA: Sorry thought I was in the VB6 forum instead of Split() function it would be .Split() in VB.Net

    as in
    Code:
    Dim PartStrings as string()=LineToSplit.Split(",")
    Last edited by DataMiser; May 21st, 2010 at 03:51 PM.
    Always use [code][/code] tags when posting code.

  3. #3
    Join Date
    Jan 2006
    Location
    Fox Lake, IL
    Posts
    15,007

    Re: ectract text from line (VBA+ACCESS)

    He said VBA/ACCESS

    (Is that ONE LINE of Description, or TWO?)

    And, whomever designed a database should be shot. Or are you just exporting it? In which case, I'd use Access to IMPORT it again
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

  4. #4
    Join Date
    Jul 2008
    Location
    WV
    Posts
    5,362

    Re: ectract text from line (VBA+ACCESS)

    So he did.. I missed that

    I assume that Split() is a part of VBA now as well, though honestly it has been a very long time since I had the need to write VBA code for anything.
    Always use [code][/code] tags when posting code.

Posting Permissions

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





Click Here to Expand Forum to Full Width

Featured