|
-
February 21st, 2000, 04:33 PM
#1
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
-
February 21st, 2000, 04:46 PM
#2
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
-
February 21st, 2000, 04:53 PM
#3
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|