Results 1 to 9 of 9

Thread: get number inside the string

  1. #1

    Thread Starter
    Lively Member chxxangie's Avatar
    Join Date
    Feb 2007
    Location
    Malaysia
    Posts
    79

    get number inside the string

    for example:
    Sampling Frequency(ms)....50

    how to get the '50' inside the string?
    the number will always at the behind of the string, but the problem is the number will not always in 2 digit.....may be 3 or 1 digit.....
    so right(str,2) cannot be used in this case.....

  2. #2
    Just Married shakti5385's Avatar
    Join Date
    Mar 2006
    Location
    Udaipur,Rajasthan(INDIA)
    Posts
    3,747

    Re: get number inside the string

    use Cstr function

  3. #3
    Frenzied Member Andrew G's Avatar
    Join Date
    Nov 2005
    Location
    Sydney
    Posts
    1,587

    Re: get number inside the string

    Will there always be the "...."? or will it sometimes be shorter or longer? Also if it changes in length, will it be the only point in the whole string, or might there be one in the name?

  4. #4

    Thread Starter
    Lively Member chxxangie's Avatar
    Join Date
    Feb 2007
    Location
    Malaysia
    Posts
    79

    Re: get number inside the string

    vb Code:
    1. Private Sub Command1_Click()
    2. Dim a
    3. Dim b
    4.  
    5. a = "Sampling Frequency(ms)....50"
    6. b = CStr(a)
    7. Label1.Caption = b
    8. End Sub

    the answer is not 50....

  5. #5

    Thread Starter
    Lively Member chxxangie's Avatar
    Join Date
    Feb 2007
    Location
    Malaysia
    Posts
    79

    Re: get number inside the string

    the '...........' is fix......just the number will change

  6. #6
    Oi, fat-rag! bushmobile's Avatar
    Join Date
    Mar 2004
    Location
    on the poop deck
    Posts
    5,592

    Re: get number inside the string

    Code:
    Private Sub Command1_Click()
        Dim lPos As Long, lNum As Long, sString As String
        
        sString = "Sampling Frequency(ms)....50"
        lPos = InStrRev(sString, ".")
        If lPos Then lNum = CLng(Mid$(sString, lPos + 1) & ".0")
    
        MsgBox lNum
    End Sub

  7. #7

    Thread Starter
    Lively Member chxxangie's Avatar
    Join Date
    Feb 2007
    Location
    Malaysia
    Posts
    79

    Re: get number inside the string

    type mismatch......... :'-(

  8. #8
    Oi, fat-rag! bushmobile's Avatar
    Join Date
    Mar 2004
    Location
    on the poop deck
    Posts
    5,592

    Re: get number inside the string

    Quote Originally Posted by chxxangie
    type mismatch......... :'-(
    i forgot a +1 which I've since added to the code above.

  9. #9

    Thread Starter
    Lively Member chxxangie's Avatar
    Join Date
    Feb 2007
    Location
    Malaysia
    Posts
    79

    Re: get number inside the string

    yeah, it works......thank you so much......

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