This documentation is archived and is not being maintained.

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


Type: System::Int64
Required. Long. Whole number that you want to locate within one of the calculated ranges.
Type: System::Int64
Required. Long. Whole number that indicates the start of the set of calculated ranges. Start cannot be less than 0.
Type: System::Int64
Required. Long. Whole number that indicates the end of the set of calculated ranges. Stop cannot be less than or equal to Start.
Type: System::Int64
Required. Long. Whole number that indicates the size of each range calculated between Start and Stop. Interval cannot be less than 1.

Return Value

Type: System::String
Returns a string representing the calculated range that contains a number.


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

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

.NET Framework

Supported in: 4, 3.5, 3.0, 2.0, 1.1, 1.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

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