Interaction.Partition Method

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

Namespace: Microsoft.VisualBasic
Assembly: Microsoft.VisualBasic (in microsoft.visualbasic.dll)

static String^ Partition (
	long long Number, 
	long long Start, 
	long long Stop, 
	long long Interval
public static String Partition (
	long Number, 
	long Start, 
	long Stop, 
	long Interval
public static function Partition (
	Number : long, 
	Start : long, 
	Stop : long, 
	Interval : long
) : String



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


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


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


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

Return Value

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

For more detailed information, see the Visual Basic topic Partition Function.

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.




Before first range

First range

Last range

After last range




"   : -1"

"  0:  4"

" 95: 99"

"100:   "




"   : 19"

" 20: 29"


"200:   "




"    : 99"

" 100: 119"


"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.

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 & ".")

Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.

.NET Framework

Supported in: 2.0, 1.1, 1.0

.NET Compact Framework

Supported in: 2.0, 1.0