Results 1 to 8 of 8
  1. #1
    rawdata is offline Novice
    Windows XP Access 2007
    Join Date
    Oct 2009
    Posts
    4

    Parsing for data in between two characters

    I have a string of data that comes from another file that looks like the following:

    $67.551($145.90)$0.00($78.35)$0.00

    What I need to do is pull out the first, second, and fourth figures as in the following:

    $67.55
    ($145.90)
    ($78.35)

    As you can see a one-digit number comes after the first figure. In this case, the number 1 comes after the first figure, which needs to be ignored:

    $67.551

    In addition, the Second and Fourth figures may or may not be negative numbers.

    Currently, I'm using the InStr function in Access, but I cannot get it to work in order to pull out these figures.



    Any ideas are greatly appreciated.

    Thanks.

  2. #2
    dcrake's Avatar
    dcrake is offline Competent Performer
    Windows XP Access 2003
    Join Date
    Aug 2009
    Posts
    435
    Are the () an indication of a negative number?
    will the 1,2 & 4 figures always have a value (Not $0.00)?
    Will the 3 & 5 values always be $0.00?
    Will the extra digit always be a 1?

  3. #3
    rawdata is offline Novice
    Windows XP Access 2007
    Join Date
    Oct 2009
    Posts
    4
    1. Yes, () is an indication of a negative number
    2. Not necessarily. Any of the desired figures (first, second, or fourth) may be negative numbers.
    3. The 3rd and 5th figures may not necessarily be $0.00

  4. #4
    dcrake's Avatar
    dcrake is offline Competent Performer
    Windows XP Access 2003
    Join Date
    Aug 2009
    Posts
    435
    Have you any influence on how you are passed the string. It's just because a function would need to examine every single character then determine what to do next. There is no simple way to split the string up. Wouldn't be so bad if there was a space between each value.

    In theory you would have to step through looking for decimal points, then back track until you found a $ then back one more to see if it is a ( then skip forward to 2 places after the decimal point then check for a ) after the 2nd decimal.

    Once you have done that for the first value you would then copy that to a variable and strip off the front of the string, then repeat the above 5 times.

    David

  5. #5
    rawdata is offline Novice
    Windows XP Access 2007
    Join Date
    Oct 2009
    Posts
    4
    the data is scraped from a website using vba. I'd be happy to entertain any excel tips on parsing the data, as well.

  6. #6
    dcrake's Avatar
    dcrake is offline Competent Performer
    Windows XP Access 2003
    Join Date
    Aug 2009
    Posts
    435
    Have you any control on how the data is scraped or access to the vba code that does it?

    If someone is providing this information for you then I imagine there is a cost involved, if so, tell them that the scrape needs revising as it is not fit for purpose.

    David

  7. #7
    rawdata is offline Novice
    Windows XP Access 2007
    Join Date
    Oct 2009
    Posts
    4
    If I had no other choice, do you have ideas around the formulas that I would use to parse the data in several steps inside Access?

  8. #8
    dcrake's Avatar
    dcrake is offline Competent Performer
    Windows XP Access 2003
    Join Date
    Aug 2009
    Posts
    435
    sstr = IncomingString

    'Where is the first . (dot)

    Code:
     
    iDot = InStr(sstr,".")
    iDollar = InStr(sstr,"$")
     
    Dollars = Mid(sstr,iDollar+1,iDot-1)
    Cents = Mid(sstr,iDot+1,2)
     
    'Test for negative 
    If Mid(sstr,iDollar-1) = "(" Then
     
       Amount = "(" & Dollars & "." & Cents & ")"
    else
       Amount = Dollars & "." & Cents 
     
    End if
    'Cut of the calculation
    sstr = mid(sstr,Len(Amount))
     
    Amount = CCur(Amount)
    This code extracts the FIRST value then Cuts that off the begginning of the string you would have to repeat this five times in a loop but only worry about the ones you want.


    EDIT
    If the first value is a negative is the extra digit inside or outside the closing bracket

    ($67.551) or ($67.55)1

    This is aircode and as such untested.

    David

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Need to delete special characters
    By tlrutledge in forum Queries
    Replies: 1
    Last Post: 08-23-2013, 03:10 AM
  2. Parsing data into something usable.
    By crownedzero in forum Import/Export Data
    Replies: 22
    Last Post: 08-05-2009, 07:18 AM
  3. parsing data in access (coding?)
    By banker247 in forum Programming
    Replies: 0
    Last Post: 01-13-2009, 12:05 PM
  4. Special Characters
    By orgelizer in forum Access
    Replies: 0
    Last Post: 03-20-2007, 08:24 PM
  5. Strings limited to 255 characters
    By ocordero in forum Programming
    Replies: 4
    Last Post: 08-09-2006, 09:13 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums