CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Feb 1999
    Posts
    21

    stupid question. how to splt a number up and only grab a certain set of them

    This is a silly question..

    I am using vb 5 presently..

    I would like to take a series of numbers like...

    55403324454

    and only keep the first 4.. I know this is fairly easy but can't figure out how to do it... mind blank...oh I want the reslut to stay a number and not a string.

    Thanks


  2. #2
    Join Date
    Feb 2000
    Location
    Indiana
    Posts
    308

    Re: stupid question. how to splt a number up and only grab a certain set of them

    It's the old "make change" problem.

    lngTemp = 55403324454
    lngPos1 = lngTemp \ 10000000000 '5
    lngTemp = lngTemp Mod 10000000000 '5403324454
    lngPos2 = lngTemp \ 1000000000 '5
    lngTemp = lngTemp Mod 1000000000 '403324454
    'etc...



    Maybe it's not the most efficient way to handle it, but I would probably do this in a pinch:

    Dim sTemp as string
    Dim iPos as Integer
    Dim iLen as Integer
    Dim arPos() as Integer

    sTemp = CString("55403324454")
    iLen = len(sTemp)

    Redim arPos(iLen)

    for iPos = 0 to (iLen - 1)
    arPos(iPos) = CInt(mid(sTemp, iPos, 1))
    next iPos






  3. #3
    Join Date
    Dec 1999
    Location
    Texas
    Posts
    96

    Re: stupid question. how to splt a number up and only grab a certain set of them

    If you always want to keep the first four, you could just use the following code:


    Function FirstFourDigits(byval Number as Long) as Long
    Dim lngReturn as Long
    '
    'get the 4 leftmost digits using the Left function.
    lngReturn = Clng(Left$(Number,4))
    'Return the value.
    FirstFourDigits = lngReturn
    '
    End Function




    Hope that helps,
    Rippin


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