Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Incrementing a decimal point 1

Status
Not open for further replies.

srmclean

Technical User
Jun 23, 2003
23
0
0
AU
I have a numbering scheme for a list of items which utilises decimal places.

When a user inputs an item number of 1 then I use a function "NexItemNumber" to work out the next number for the next record, in this case 2. That is no real problem with integers, but how would I be able to generate the following real "NextItemNumber"s ?

Item 1.1 next = 1.2
Item 1.01 next = 1.02
Item 1.001 next = 1.002

I've seen similar threads but nothing this specific.

Anyone with any ideas?

Shaun

----------------
Shaun McLean
 
Here's a sample function that will do the trick. I hav'nt commented it, but hopefully you can step through it and understand what its doing.
Code:
Function GetNextNumber(YourNum)

   strYourNum = Trim(Str(YourNum))
   DecimalPosition = InStr(strYourNum, ".")
   If DecimalPosition = 0 Then DecimalPosition = Len(strYourNum)

   NumberLength = Len(strYourNum)
   LengthAfterDecimal = NumberLength - DecimalPosition

   YourNumWhole = YourNum * 10 ^ LengthAfterDecimal
   YourNumWholeInc = YourNum * 10 ^ LengthAfterDecimal + 1
   YourNumInc = YourNumWholeInc * (10 ^ -LengthAfterDecimal)

   GetNextNumber = YourNumInc
End Function

Sample invocations: GetNextNumber(1.01) returns 1.02
GetNextNumber(2) returns 3



Steve Lewy
Solutions Developer
steve@lewycomputing.com.au
(dont cut corners or you'll go round in circles)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top