Partition Function


Partition Function

Class

Microsoft.VisualBasic.Interaction

Syntax

     Dim result As String = Partition(number, start, stop, interval) 


number (required; Long)

Number to evaluate against the intervals.


start (required; Long)

Start of the range. Must be nonnegative.


stop (required; Long)

End of the range. Must be greater than start.


interval (required; Long)

Size of each interval into which the range is partitioned.

Description

The Partition function returns a string that describes which interval contains number. The format returned is x:y, where x is the start of the range, and y is the end of the range.

Usage at a Glance

  • Partition returns a range formatted 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 stop, plus one. This ensures that the interval text will be handled properly during any sort operations.

  • If number is outside of the range of start, the range reported is :y, where y is start - 1, and no value exists before the colon.

  • If number is outside the range of end, the range reported is x:, where x is end + 1, and no value exists after the colon.

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

  • The Partition function is useful in creating histograms, which give the number of integers from a collection that fall into various ranges.

Example

The code:

     Dim counter As Integer     For counter = -1 To 110 \ 5        Console.WriteLine(CStr(counter * 5) & " is in interval " & _           Partition(counter * 5, 0, 100, 10))     Next counter 

produces the following output:

     -5 is in interval    : -1     0 is in interval   0:  9     5 is in interval   0:  9     10 is in interval  10: 19     15 is in interval  10: 19     20 is in interval  20: 29     25 is in interval  20: 29     30 is in interval  30: 39     35 is in interval  30: 39     40 is in interval  40: 49     45 is in interval  40: 49     50 is in interval  50: 59     55 is in interval  50: 59     60 is in interval  60: 69     65 is in interval  60: 69     70 is in interval  70: 79     75 is in interval  70: 79     80 is in interval  80: 89     85 is in interval  80: 89     90 is in interval  90: 99     95 is in interval  90: 99     100 is in interval 100:100     105 is in interval 101:     110 is in interval 101: 

Version Differences

  • The Partition function did not exist in VB 6, although it was available in Microsoft Access.




Visual Basic 2005(c) In a Nutshell
Visual Basic 2005 in a Nutshell (In a Nutshell (OReilly))
ISBN: 059610152X
EAN: 2147483647
Year: 2004
Pages: 712

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net