Results 1 to 5 of 5
  1. #1
    2 Star Lounger
    Join Date
    Jul 2003
    Location
    Park City, Utah
    Posts
    189
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Parsing Variable Contents (Word XP VBA)

    I am collecting a date/time field in the variable strAdmDate which sometimes includes the time and sometimes does not. It is always in mm/dd/yyyy hh:mm format. How do I parse the contents to keep only the first 10 characters of the variable contents?

    By the way, thanks to all for your help. Your quick responses, helpful hints and outright complimentary coding enable me to do my job...and enjoy it!

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Parsing Variable Contents (Word XP VBA)

    You can use the Left function:

    strAdmDate = Left(strAdmDate, 10)

    will chop off everything after the tenth character.

  3. #3
    Gold Lounger
    Join Date
    Dec 2000
    Location
    New Hampshire, USA
    Posts
    3,386
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Parsing Variable Contents (Word XP VBA)

    First check that the length is at least 10, otherwise an error will get generated.

  4. #4
    Gold Lounger
    Join Date
    Dec 2000
    Location
    New Hampshire, USA
    Posts
    3,386
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Parsing Variable Contents (Word XP VBA)

    If I understand correctly, you have something like:

    strAdmDate = SomeSortOfExpressionThatReturnsADate/Time

    If so, the preferred solution would be to use something like:

    strAdmDate = Format(SomeSortOfExpressionThatReturnsADate/Time, "mmm d yyyy")

    This assumes you wish to only retain the date porttion of whatever is in SomeSortOfExpressionThatReturnsADate/Time.

  5. #5
    Bronze Lounger
    Join Date
    Nov 2001
    Location
    Arlington, Virginia, USA
    Posts
    1,394
    Thanks
    0
    Thanked 3 Times in 3 Posts

    Re: Parsing Variable Contents (Word XP VBA)

    About the only way you'll get an error with Left function is if you try to pass Null value as string argument to Left$ version of function. If you pass a string whose length is less than value passed as 2nd argument (length), the function will simply return original string. Example:

    ? Left("ABC",10)
    ABC

    ? Len(Left("",10))
    0 (returns zero-length string)

    ? Left(123,10)
    123

    ? Left(Null,10)
    Null (variant version of function returns Null)

    ? Left$(Null,10)
    Results in error: <Err 94 - Invalid use of Null>

Posting Permissions

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