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?
Printable View
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?
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.
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. :)
another option would be
12345678 \ 10000 'integer division
and
12345678 mod 10000
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"
-------------------------------