Signature (Visual Basic / VBA)
Public Function RandomVariant( _
Optional ByVal vVarType As Variant _
) As Variant
Code Examples
? Rnd(-1)
0.224007
? IllustrateDebug(RandomVariant())
True (Boolean)
? IllustrateDebug(RandomVariant())
46 (Byte)
? IllustrateDebug(RandomVariant())
699 (Integer)
? IllustrateDebug(RandomVariant())
True (Boolean)
? IllustrateDebug(RandomVariant())
-854099670 (Long)
? IllustrateDebug(RandomVariant(vbSingle))
-1.255436E+38 (Single)
? IllustrateDebug(RandomVariant(vbDate))
10/16/9852 12:11:43 PM (Date)
? IllustrateDebug(RandomVariant(vbString))
"¶v^NÎåà ù^Q%140" (String * 11)
vbArray not supported.
vbDataObject not supported.
vbError not supported.
vbObject not supported.
Parameters
| Parameter | Description |
|---|---|
| vVarType | The numeric constant which represents a specific Visual Basic data type. vVarType should either be 1) the value of one of the Visual Basic vb constants that represents a data type if the function is to return a random value of that type, or 2) missing or Null in which case the function will randomly select the type of value to return as well. |
Notes & Version History
| Note | The call to the Visual Basic Rnd function in the above example seeds the Visual Basic random number generator so that the sample results can be reproduced. There is generally no need to call the Rnd function within your programs since Entisoft Tools initializes the Visual Basic random number generator once with "Randomize" statement. |
| Note | This function can generate random values of the following types: Boolean, Byte, Currency, Date, Decimal, Double, Empty, Integer, Long, Null, Single, and String. Function returns Null if vVarType is the vb constant representing one of the supported data types. |
| Note | When generating random strings, this function uses RandomIntegerWithinExpRange (0, 64, 2) to determine the length of the string, and it uses an alphabet containing every character whose ASCII value is between 0 and 255. |