Partition Function

Description

Returns a string indicating where a number occurs within a calculated series of ranges.

Syntax

Partition( number, start, stop, interval )

Remarks

The Partition function identifies the particular range in which number falls and returns a string describing that range.  The Partition function is most useful in queries.  You can create a select query that shows how many orders fall in various ranges (for example, order values from 1 to 1000, 1001 to 2000, and so on).

The Partition function uses the following parts:

Part                 Description

number             Long number that you want to evaluate against the ranges.

start                 Long number that is the start of the overall range of numbers.  It can't be less than 0.

stop                  Long number that is the end of the overall range of numbers.  It can't be equal to or less than start.

interval             Long number that is the interval spanned by each range in the series from start to stop.  It can't be less than 1.

The following table shows how the ranges are determined using three sets of start, stop, and interval parts.  The First Range and Last Range columns illustrate the text Partition returns.  The ranges are represented by lowervalue:uppervalue, where the low end (lowervalue) of the range is separated from the high end (uppervalue) with a colon ( : ).

start    stop      interval    Before First     First Range      Last Range      After last

0        99          5        "   : -1"              "  0:  4"           " 95: 99"              " 100:   "
20      199        10        "    :  19"         "  20:  29"       " 190: 199"           " 200:    "
100     1010        20        "     :   99"      "  100:  119"   " 1000: 1010"       " 1011:     "

In this table, the third line shows the result when start and stop define a set of numbers that can't be evenly divided by interval. The last range extends to stop (11 numbers) even though interval is 20.

If necessary, Partition returns a range with enough leading spaces so that there are the same number of characters to the left and right of the colon as there are characters in the stop part, plus one.  This ensures that if you use Partition with other numbers, the resulting text will be handled properly during any subsequent sort operation.

If interval is 1, the range is number:number, regardless of the start and stop arguments.  For example, if interval is 1, number is 100 and stop is 1000, Partition returns "  100:  100".

If any of the parts is Null, Partition returns a Null.

Distribution Note   When you create and distribute applications that use this function in your code, you should install the file MSAFINX.DLL in the customer's Microsoft Windows \SYSTEM directory.  The Visual Basic Setup Kit provides tools to help you write setup programs that install your applications.