Click to See Complete Forum and Search --> : stupid question. how to splt a number up and only grab a certain set of them
Aaron
February 21st, 2000, 03:33 PM
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
Kyle Burns
February 21st, 2000, 03:46 PM
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
Rippin
February 21st, 2000, 03:53 PM
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
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.