Notes for
http://www.snb-vba.eu/VBA_Arrays_en.html
http://www.excelfox.com/forum/showth...0174#post10174 https://www.excelforum.com/the-water...ml#post4613906
Code:
Sub snbsVarTypeTypeName() ' http://www.snb-vba.eu/VBA_Arrays_en.html http://www.excelfox.com/forum/showthread.php/2157-Re-Defining-multiple-variables-in-VBA?p=10174#post10174 https://www.excelforum.com/the-water-cooler/1174400-would-like-to-know-about-the-forum-experts-gurus-4.html#post4613906
a_sn = Array(1, 2, 3, 4)
a_sp = Split("1,2,3,45", ",")
a_sq = Range("A1:F5") ' defaluts to Range("A1:F5").Value ' .Value Property returns a Field ( Arrray ) of Variant Member Elements
Dim a_st As Shape: x = VarType(a_st) ' 9 ( Object )
Rem 2 VarType Constants https://msdn.microsoft.com/en-us/library/office/gg251422.aspx
Dim VrTpe As Long
'2a) Variant Variables: You can determine how the data in a Variant is treated..
Dim Var As Variant: VrTpe = VarType(Var) ' 0 vbEmpty Uninitialized (default)
Dim VarDef: Let VrTpe = VarType(VarDef) ' 0
Let Range("A25:A26").Value2 = "Some text" ' .Value2 gives you the underlying value of the cell (could be empty, string, error, number (double) or boolean) ' .Value gives you the same as .Value2 except if the cell was formatted as currency or date it gives you a VBA currency (which may truncate decimal places) or VBA date.
Let Var = Range("A25:A26").Text ' "Some text" given to Variant attempts to coerce to a String and will fail if the underlying Variant is not coercable to a String type
Let Range("A26").Value = "Some other text" ' .Value gives you the same as .Value2 except if the cell was formatted as currency or date it gives you a VBA currency (which may truncate decimal places) or VBA date.
Let Var = Range("A25:A26").Text ' The data is invalid, a Null is given to Variant
Let VrTpe = VarType(Var) ' 1 Contains no valid data
Dim arrVar(1 To 1) As Variant
Let VrTpe = VarType(arrVar())
'2b) Normal Variables
Dim Intr As Integer: VrTpe = VarType(Intr) ' 2
Dim Lng As Long: VrTpe = VarType(Lng) ' 3
Dim Sngle As Single: VrTpe = VarType(Sngle) ' 4
Dim Dble As Double: VrTpe = VarType(Dble) ' 5
Dim Str As String: VrTpe = VarType(Str) ' 8
Dim Obj As Object: VrTpe = VarType(Obj) ' 9
VrTpe = VarType(a_sn) ' 8204 = 8192 (array) + 12 (Variant)
VrTpe = VarType(a_sp) ' 8200 = 8192 (array) + 8 (String)
VrTpe = VarType(a_sq) ' 8204 = 8192 (array) + 12 (Variant) ' a_sq defaults to a_sq.Value, or rather the = string refs to cells which returns a a Field ( Arrray ) of Variant Member Elements
VrTpe = VarType(a_st) ' 9 (object)
Dim a_bt(1 To 1) As Byte
Let VrTpe = VarType(a_bt()) ' 8209 = 8192 (array) + 17 (Byte)
Dim Rnga_sq As Range: Set Rnga_sq = Range("A1:F5")
Let VrTpe = VarType(Rnga_sq) ' 8204 = 8192 (array) + 12 (Variant (used only for arrays of Variants)) !!!! VarType interprets a Range as an array. ???????
End Sub
Sub TextValueValue2() ' https://fastexcel.wordpress.com/2011/11/30/text-vs-value-vs-value2-slow-text-and-how-to-avoid-it/ http://stackoverflow.com/questions/17359835/what-is-the-difference-between-text-value-and-value2
Set c = Range("A27")
c.Value = 1198.3
c.NumberFormat = "$#,##0_);($#,##0)"
MsgBox c.Value
MsgBox c.Text
MsgBox c.Value2
End Sub
Sub M_snb()
sn = Array(String(300, "p"), String(700, "p"), Space(500))
Dim v
MsgBox Len(sn(0)) & vbLf & Len(sn(1)) & vbLf & Len(sn(2))
End Sub
Using Excel 2007 32 bit
https://msdn.microsoft.com/en-us/lib.../gg251422.aspx |
|
|
|
|
|
|
|
|
Normal Variable |
0 |
vbEmpty Uninitialized |
|
|
|
|
|
|
Array Variable |
8192 |
Array ( Member elements Empty ) |
|
|
|
|
|
|
Normal Variable |
1 |
If data is invalid, a Null is given to Variant |
|
|
|
|
|
|
Array Variable |
8193 |
Null |
|
|
|
|
|
|
Normal Variable |
2 |
Integer |
|
6 |
Currency |
|
11 |
Boolean |
Array Variable |
8192+2=8194 |
|
|
8198 |
|
|
8203 |
|
Normal Variable |
3 |
Long |
|
7 |
Date |
|
12 |
------- |
Array Variable |
8195 |
|
|
8199 |
|
|
8204 |
Variant (used only for arrays of variants) |
Normal Variable |
4 |
Single |
|
8 |
String |
|
17 |
Byte |
Array Variable |
8196 |
|
|
8200 |
|
|
8146 |
|
Normal Variable |
5 |
Double |
|
9 |
Object |
|
36 |
UserDefined |
Array Variable |
8197 |
|
|
8201 |
|
|
8228 |
|
Normal Variable |
6 |
Currency |
|
|
|
|
|
|
Array Variable |
8198 |
|
|
|
|
|
|
|
Normal Variable |
7 |
Date |
|
|
|
|
|
|
Array Variable |
8199 |
|
|
|
|
|
|
|
Normal Variable |
8 |
String |
|
|
|
|
|
|
Array Variable |
8200 |
|
|
|
|
|
|
|
Normal Variable |
9 |
Object |
|
|
|
|
|
|
Array Variable |
8201 |
|
|
|
|
|
|
|
Normal Variable |
10 |
Error |
|
|
|
|
|
|
Array Variable |
8202 |
|
|
|
|
|
|
|
Normal Variable |
11 |
Boolean |
|
|
|
|
|
|
Array Variable |
8203 |
|
|
|
|
|
|
|
Normal Variable |
12 |
------- |
|
|
|
|
|
|
Array Variable |
8204 |
Variant (used only for arrays of variants) |
|
|
|
|
|
|
Normal Variable |
17 |
Byte |
|
|
|
|
|
|
Array Variable |
8209 |
|
|
|
|
|
|
|
Normal Variable |
36 |
UserDefined |
|
|
|
|
|
|
Array Variable |
8228 |
|
|
|
|
|
|
|
Worksheet: EmptiesVariables
Bookmarks