baNumbers is a (mainly targeted at VB6/VBA) array and numbers helper library.
The DLL is written in PowerBASIC (PBWIN 6.04), the source of the DLL is the file baNumbers.bas, located in the root of the repository.
The folder VB contains a VB6 demonstration project. The VB prototypes (aka 'Declarations') are located in the file VB\BAS\baNumbers.bas. You'll find some other VB helper functions in this folder, too.
Each of the following methods takes an array of the respective data type as input and sorts the array data in ascending order. Please note that the array is passed ByRef, i.e. the original array will be altered.
Sub baSortByte(a() As Byte)
Sub baSortCurrency(a() As Currency)
Sub baSortDouble(a() As Double)
Sub baSortInteger(a() As Integer)
Sub baSortLong(a() As Long)
Sub baSortSingle(a() As Single)Each of the following methods takes an array of the respective data type as input and computes and returns the median of the array contents.
Function baMedianByte(a() As Byte) As Byte
Function baMedianCurrency(a() As Currency) As Currency
Function baMedianDouble(a() As Double) As Double
Function baMedianInteger(a() As Integer) As Integer
Function baMedianLong(a() As Long) As Long
Function baMedianSingle(a() As Single) As SingleEach of the following methods takes an array of the respective data type as input and sets all array elements to the provided value. Please note: the Currency data type is not supported.
Function baSetByte(a() As Byte, ByVal value As Byte) As Boolean
Function baSetInteger(a() As Integer, ByVal value As Integer) As Boolean
Function baSetLong(a() As Long, ByVal value As Long) As Boolean
Function baSetSingle (a() As Single, ByVal value As Single) As Boolean
Function baSetDouble (a() As Double, ByVal value As Double) As BooleanThis method fills a Currency array with random numbers within 0 <= x <= 1.
Sub baRndArray (a() As Currency)This method fills a Long array with random numbers within lLower <= x <= lUpper.
Sub baRndRangeArray (a() As Long, ByVal lLower As Long, ByVal lUpper As Long)Sorts/reorders 2 arrays. The first array a1() will be sorted. The second array a2() however will have its array elements arranged as if they "stick" to the first array, i.e. when a1() is sorted and element a1(1) has become element a1(5) thereafter, a2(1) now also will be a2(5). The arrays may be of different data types.
Please note: the second array must have at least the same number of elements than the first array.
-
eDataType1, eDataType2
Data type of the respective array -
bolDescending
IfTrue, sort array 1 descending order.
Enum eArrayDataType
adtByte = 0
adtCurrency = 1
adtDouble = 2
adtInteger = 3
adtLong = 4
adtSingle = 5
adtString = 6
End EnumFunction baSort2Arrays Lib "baNumbers.dll" (ByVal eDataType1 As eArrayDataType, eDataType2 As eArrayDataType, Optional ByVal bolDescending As Boolean = False) As LongThe function returns the following error codes:
- 0 = Success
- 1 = Invalid data type passed in
eDataType
Each of the following methods takes an array of the respective data type as input and sorts the array data in ascending order. Please note that the array is passed ByRef, i.e. the original array will be altered.
Sub baSortByte(a() As Byte)
Sub baSortCurrency(a() As Currency)
Sub baSortDouble(a() As Double)
Sub baSortInteger(a() As Integer)
Sub baSortLong(a() As Long)
Sub baSortSingle(a() As Single)Each of the following methods returns the fractional part of the floating point number.
Function baFracCur(ByVal curValue As Currency) As Currency
Function baFracDouble(ByVal dblValue As Double) As Double
Function baFracSingle(ByVal fValue As Single) As SingleEach of the following methods swaps the value of two variables.
Function baSwapByte(ByRef v1 As Byte, ByRef v2 As Byte) As Boolean
Function baSwapCurrency(ByRef v1 As Currency, ByRef v2 As Currency) As Boolean
Function baSwapDouble(ByRef v1 As Double, ByRef v2 As Double) As Boolean
Function baSwapInteger(ByRef v1 As Integer, ByRef v2 As Integer) As Boolean
Function baSwapLong(ByRef v1 As Long, ByRef v2 As Long) As Boolean
Function baSwapSingle(ByRef v1 As Single, ByRef v2 As Single) As BooleanThe following methods return the unsigned value of a (negative) signed integer value, i.e. Integer to Word etc.
Please note: due to VB's data type limitation, some values are returned as Currency to avoid overflow errors.
Function Int2Wrd(ByVal iValue As Integer) As Long
Function Int2DWrd(ByVal iValue As Integer) As Currency
Function Lng2DWrd(ByVal lValue As Long) As Currency
Function Lng2Quad(ByVal lValue As Long) As CurrencyReturns the string representation of number, formatted according to the locale settings.
Function baFormatNumber (ByVal curNumber As Currency, _
ByVal wLangLocale As Long, ByVal wSubLangLocale As Long) As StringReturns the string representation of a number, formatted according to LANGID.
Function baFormatNumberEx(ByVal curNumber As Currency, _
ByVal dwLangID As Long) As StringDetermines the specific Variant subtype, e.g.
Dim l As Long, v As Variant
v = l
' Prints "3" = eVariantType.vtLongIntegerSigned
Debug.Print TypeOfVariant(v)Please note that arrays will report as vtArray of vt(DataType). e.g.
Dim i(1 To 2) As Integer, v As Variant
v = i
' Prints "8194" = eVariantType.vtArray Or eVariantType.vtIntegerSigned
Debug.Print TypeOfVariant(v)Function TypeOfVariant (ByVal vnt As Variant) As eVariantTypeReturn the string representation of the variant subtype
Function baTypeOfVariantToString(ByVal eValue As eVariantType) As String