Results 1 to 5 of 5

Thread: Urgent, Please help

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Feb 2000
    Posts
    20
    how can i just take some park of a nomber, like a = 12345678 but i just want the begining 4 digit to assign to b or may be the middle 4 digit or the last 4 digit, how?

  2. #2
    Lively Member
    Join Date
    Jun 1999
    Location
    East Anglia, England
    Posts
    73
    Hello,
    Look up the following in the VB Help files,
    Mid,
    Left,
    Right,

    These should help you to extract anything from anywhere from a string.

    Desire.

  3. #3
    Fanatic Member Stevie's Avatar
    Join Date
    Mar 2000
    Location
    London, UK
    Posts
    565
    I think you could probably turn the number into a string, then use some string manipulation functions, then turn is back into a number.

    Eg :

    ' number into string
    strNumber = cstr(12345)

    ' get first 3 digits
    strFirst3Digits = Left$(strNumber, 3)

    ' string into number
    intNumber = cint(strFirst3Digits)

    Hope this helps.

  4. #4
    Frenzied Member Mark Sreeves's Avatar
    Join Date
    Nov 1999
    Location
    UK
    Posts
    1,845
    another option would be

    12345678 \ 10000 'integer division

    and

    12345678 mod 10000
    Mark
    -------------------

  5. #5
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    I have a function for it:
    -------------------------------Code
    Function numdigit(num, startdigit, lendigit)
    If Not IsNumeric(num) Then Exit Function
    If (startdigit + lendigit) > Len("" & num) Then Exit Function
    numdigit = Val(Mid("" & num, startdigit, lendigit))
    End Function
    -------------------------------
    To use it:
    -------------------------------Code
    Debug.Print numdigit(12345678, 2, 4)
    'shoud show "2345"
    -------------------------------

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