CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5

Thread: Convert string

  1. #1
    Join Date
    Aug 2000
    Location
    NY, USA
    Posts
    632

    Convert string

    Although it's very easy to write my own function to convert the string, presented by digits, commas and dots to Long, I would ask, maybe somebody knows good source of string manipulation functions. I just do not want to invent bycicle.
    Thank you.
    Vlad


  2. #2
    Join Date
    Dec 1999
    Location
    Dublin, Ireland
    Posts
    1,173

    Re: Convert string

    You could use the VB command CLng thus:

    Dim lVal

    lVal = CLng("1,000.00")




    HTH,
    Duncan

    -------------------------------------------------
    Ex. Datis: Duncan Jones
    Merrion Computing Ltd
    http://www.merrioncomputing.com
    '--8<-----------------------------------------
    NEW -The printer usage monitoring application
    '--8<------------------------------------------

  3. #3
    Join Date
    Aug 2000
    Location
    NY, USA
    Posts
    632

    Re: Convert string

    Just try this function with deleted first digit, i.e ",000.00".



  4. #4
    Join Date
    Dec 1999
    Location
    Dublin, Ireland
    Posts
    1,173

    Re: Convert string

    yes - but that isn't a meaningful number.

    To extract the number portion of a string:

    '\\ --[IntlAwareVal]--------------------------------------------------
    '\\ The Val function is not internationally aware, but provides more
    '\\ functionality than the internationally aware "CDbl" so this
    '\\ is a replacement for both
    '\\ ----------------------------------------------------------------------
    public Function IntlAwareVal(byval sIn as string) as Double

    '\\ Add a zero at the front to cope with empty strings
    If IsNumeric("0" & Trim$(sIn)) then
    sIn = "0" & Trim$(sIn)
    End If

    If IsNumeric(Trim$(sIn)) then
    IntlAwareVal = CDbl(Trim$(sIn))
    else
    IntlAwareVal = Val(Trim$(sIn))
    End If

    End Function






    -------------------------------------------------
    Ex. Datis: Duncan Jones
    Merrion Computing Ltd
    http://www.merrioncomputing.com
    '--8<-----------------------------------------
    NEW -The printer usage monitoring application
    '--8<------------------------------------------

  5. #5
    Join Date
    Aug 2000
    Location
    NY, USA
    Posts
    632

    Re: Convert string

    Yes, comma is not a meaningful character, but imagine a situation, when project contains thousands of input controls (Textboxes, combos and so on), almost all have some kind of validation, data is formatted either while user enters it or after control loses its focus. So far everything was OK, today somebody tried to delete first digit from 2,222.00. Run Time error occured, because that value was going to be converted with CDbl. So, I'd like to see already created by somebody string manipulation functions in order to select some of them for this project, or at least to find out, what kind of conversion is sometime required.
    Vlad


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