CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Sep 2006
    Posts
    32

    Is there a better VAL()?

    As you know, Val() stops at commas, parentheses, etc, but ignores spaces between separate numbers!
    CDBL(strTxt) offers help, but only if the string is fully numeric

    I often write code to process copied text, and want to extract The number in a line like this
    Profit/Loss: ($12,000.95) -- thru July

    Is there a function for this, or do I have to write one myself?
    Appreciate any help

  2. #2
    Join Date
    Jul 2006
    Location
    Germany
    Posts
    3,725

    Re: Is there a better VAL()?

    I think you'd have to make use of the string functions to locate and extract numeric values from text.
    If you are sure to have the $ leading a number you can locate it with InStr().
    If the $ is not to be expected always, you'd have to walk through the string character by character until the first numeric digit.
    Then you walk throiugh the following characters until the next non-numeric (accepting "," and ".").
    Then you'd use Mid$ to extract the substring and then, if you want to use the CDbl() or Val(), you'd have to use Replace() to remove the comma.

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