Page 1 of 2 12 LastLast
Results 1 to 15 of 27
  1. #1
    DOSRoss is offline Novice
    Windows 7 64bit Access 2007
    Join Date
    Apr 2015
    Posts
    17

    Extract number from String

    My ultimate objective is to parse thru a line similar to that below:



    adocExecuteComplete| SQL Request exceeded reasonable time, adocVER2_CAD: 6627ms elapsed, type cmdText, status esOK, cursor ctUnspecified, lock ltReadOnly, records 1

    I need to extract the "6627" as a number to a field ...
    the number can be 1 to 99999
    the number is almost always followed directly by "ms" (those are the only ones I need to collect right now)

    I would also like to extract the string from the beginning up to the number into another field in the database

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,525
    Code:
    =left[field],4)

  3. #3
    DOSRoss is offline Novice
    Windows 7 64bit Access 2007
    Join Date
    Apr 2015
    Posts
    17
    I am sorry ... I don't understand your reply.
    I need to find the "ms" ... examine to see if a digit precedes it
    If so, how many digits precedes the "ms" and extract those to a field

  4. #4
    CJ_London is offline VIP
    Windows 8 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,424
    don't think left will hack it - range is 0-99999

    providing the text always starts with a number try using the val function instead

    val("123abc") with return 123
    val("12345xyz") will return 12345

    even works for decimals
    val("12.3abc") with return 12.3

    but not currency
    val($12.3aaa") will return 0

  5. #5
    orange's Avatar
    orange is offline Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,725
    How about telling us the overall need/opportunity?
    Don't focus on the 1 single issue facing you at the moment.
    Plan what you are going to do based on the requirements you know.
    You can implement your How's based on the business priorities; but designing 1 thing at a time is a poor strategy, generally.
    What is the big picture from the 30,000 ft overview.

    Why do you have to parse? Where does the data come from? If possible, can they provide what you need since they are giving you output?

    This looks like error analysis of some sort????

  6. #6
    CJ_London is offline VIP
    Windows 8 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,424
    Just realised it is the whole string

    val(mid("adocExecuteComplete| SQL Request exceeded reasonable time, adocVER2_CAD: 6627ms elapsed, type cmdText, status esOK, cursor ctUnspecified, lock ltReadOnly, records 1",instr("adocExecuteComplete| SQL Request exceeded reasonable time, adocVER2_CAD: 6627ms elapsed, type cmdText, status esOK, cursor ctUnspecified, lock ltReadOnly, records 1",":")+1))

    returns 6627

    or code

    val(mid([myField],instr([myfield],":")+1))

  7. #7
    DOSRoss is offline Novice
    Windows 7 64bit Access 2007
    Join Date
    Apr 2015
    Posts
    17
    I start with a text file and bring it into Access 2007
    This is a log of 'actions' in a SQL db.

    My whole objective is to get the "Line Number" which will is separated when the txt file is imported and the "ms" number.
    That is really all I need to report on from the text file.
    I am having a challenge to get that number precisely.

    There would be many lines in the log that have "ms" (i.e. 'msg') but not a number precede it.
    If there is a single digit before the 'ms' then there may be as many as five more.

  8. #8
    DOSRoss is offline Novice
    Windows 7 64bit Access 2007
    Join Date
    Apr 2015
    Posts
    17
    preceding the number that I am attempting to extract could be any number of text items ... the ':' is not always in front of the number.

  9. #9
    DOSRoss is offline Novice
    Windows 7 64bit Access 2007
    Join Date
    Apr 2015
    Posts
    17
    "pseudo code"

    take the record of a database
    inspect Field4 to see if the text "ms" is present
    if so ...
    check to see if there is a digit that precedes it .. i.e. '5ms'
    if so ...
    check to see how many digits precede the 'ms' ... i.e. '54321ms'
    if there are as many as five
    keep the five digit (or 4, or 2, etc) number - update it to field5 of the same record
    Go on to the next record

  10. #10
    DOSRoss is offline Novice
    Windows 7 64bit Access 2007
    Join Date
    Apr 2015
    Posts
    17
    This works for every instance that there is a ":" preceding the number, but that is only about half of the time, if that many.

  11. #11
    CJ_London is offline VIP
    Windows 8 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,424
    can you guarantee that 'ms' or perhaps 'ms ' will never appear prior to where you expect to see it?
    are there records which have 'ms' or 'ms ' but in a different context (implication is you will)

  12. #12
    DOSRoss is offline Novice
    Windows 7 64bit Access 2007
    Join Date
    Apr 2015
    Posts
    17
    Quote Originally Posted by Ajax View Post
    Just realised it is the whole string

    val(mid("adocExecuteComplete| SQL Request exceeded reasonable time, adocVER2_CAD: 6627ms elapsed, type cmdText, status esOK, cursor ctUnspecified, lock ltReadOnly, records 1",instr("adocExecuteComplete| SQL Request exceeded reasonable time, adocVER2_CAD: 6627ms elapsed, type cmdText, status esOK, cursor ctUnspecified, lock ltReadOnly, records 1",":")+1))

    returns 6627

    or code

    val(mid([myField],instr([myfield],":")+1))
    Reply:
    This works for every instance that there is a ":" preceding the number, but that is only about half of the time, if that many.

  13. #13
    Perceptus's Avatar
    Perceptus is offline Expert
    Windows 7 64bit Access 2007
    Join Date
    Nov 2012
    Location
    Knoxville, Tennessee
    Posts
    659
    I vaguely remember something along the lines of SQL being slow when casting data to another type or converting.

  14. #14
    DOSRoss is offline Novice
    Windows 7 64bit Access 2007
    Join Date
    Apr 2015
    Posts
    17
    Quote Originally Posted by Ajax View Post
    can you guarantee that 'ms' or perhaps 'ms ' will never appear prior to where you expect to see it?
    are there records which have 'ms' or 'ms ' but in a different context (implication is you will)
    Reply:
    The 'log' that contains the source data is all time based. the 'ms' is for millisecond obviously.
    The exact 'ms' construction follows the data I am trying to collect. ie 234ms, or 1234ms etc.
    anything with 'ms ' or 'msg' or 'ms -anything' would not have a digit preceding it ... or multiple digits

  15. #15
    DOSRoss is offline Novice
    Windows 7 64bit Access 2007
    Join Date
    Apr 2015
    Posts
    17
    Finding the 'ms' and parsing backwards thru the string, until all the digits are collected, is probably the best direction.

Page 1 of 2 12 LastLast
Please reply to this thread with any new information or opinions.

Similar Threads

  1. Extract part of string
    By Fais in forum Access
    Replies: 5
    Last Post: 08-06-2014, 04:46 PM
  2. Extract a number from a string
    By webisti in forum Access
    Replies: 3
    Last Post: 09-16-2013, 08:29 AM
  3. Extract Value from Variable in String
    By nguyenak in forum Programming
    Replies: 3
    Last Post: 05-24-2012, 03:50 PM
  4. Extract String From Between 2 Values
    By kathleencampbell in forum Queries
    Replies: 5
    Last Post: 03-23-2012, 10:52 AM
  5. Convert Number to String in .csv extract
    By CindyR19 in forum Import/Export Data
    Replies: 3
    Last Post: 08-17-2011, 02:58 PM

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