Interaction.Partition(Int64, Int64, Int64, Int64) Method

Definition

Returns a string representing the calculated range that contains a number.

public:
 static System::String ^ Partition(long Number, long Start, long Stop, long Interval);
public static string Partition (long Number, long Start, long Stop, long Interval);
static member Partition : int64 * int64 * int64 * int64 -> string
Public Function Partition (Number As Long, Start As Long, Stop As Long, Interval As Long) As String

Parameters

Number
Int64

Required. Long. Whole number that you want to locate within one of the calculated ranges.

Start
Int64

Required. Long. Whole number that indicates the start of the set of calculated ranges. Start cannot be less than 0.

Stop
Int64

Required. Long. Whole number that indicates the end of the set of calculated ranges. Stop cannot be less than or equal to Start.

Interval
Int64

Required. Long. Whole number that indicates the size of each range calculated between Start and Stop. Interval cannot be less than 1.

Returns

A string representing the calculated range that contains a number.

Exceptions

Start < 0, Stop <= Start, or Interval < 1.

Examples

The following example sets up a series of ranges for decades from 1950 through 2049. It locates the value of year within the appropriate range and returns a String value showing the range. If year has a value of 1984, for example, Partition returns "1980:1989".

Dim year As Long = 1984
' Assume the value of year is provided by data or by user input.
Dim decade As String
decade = Partition(year, 1950, 2049, 10)
MsgBox("Year " & CStr(year) & " is in decade " & decade & ".")

Remarks

The Partition function calculates a set of numeric ranges, each containing the number of values specified by Interval. The first range begins at Start, and the last range ends at Stop. The Partition function then identifies which range contains Number and returns a string describing that range. The range is represented in the string as "lowervalue:uppervalue", where the low end of the range (lowervalue) is separated from the high end (uppervalue) by a colon (:).

If necessary, the Partition function inserts leading spaces before lowervalue and uppervalue so that they both have the same number of characters as the string representation of the value (Stop + 1). This ensures that if you use the output of the Partition function with several values of Number, the resulting text will be handled properly during any subsequent sort operation.

The following table shows some sample strings for ranges calculated using three sets of Start, Stop, and Interval. The "First range" and "Last range" columns show the lowest and highest ranges possible given the values of Start and Stop. The "Before first range" and "After last range" columns show the strings returned for values of Number less than Start and greater than Stop, respectively.

Start Stop Interval Before first range First range Last range After last range
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 the preceding table, the third line shows the result when Start and Stop define a set of numbers that cannot be evenly divided by Interval. The last range ends at Stop, making it only 11 numbers long, even though Interval is 20.

If Interval is 1, the range is "Number:Number", regardless of the Start and Stop arguments. For example, if Number is 267, Stop is 1000, and Interval is 1, Partition returns " 267: 267".

Partition can be useful when constructing database queries. You can create a SELECT query that shows how many orders occur within various value ranges, for example with invoice values from 1 to 1000, 1001 to 2000, and so on.

Applies to