Can someone help with (or a link to) explanation between
Dim xyz as variant
Dim xyz () as Integer, or string ?
Dim xyz (0)
I nee to upskill a bit on arrays.
Thanks.
Can someone help with (or a link to) explanation between
Dim xyz as variant
Dim xyz () as Integer, or string ?
Dim xyz (0)
I nee to upskill a bit on arrays.
Thanks.
I rarely use arrays; pretty much only when I have to use the Split() function. I use:
Dim strInvoices() As String
Aren't both Arrays? I find both work with Split.
Dim xyz as Variant - This enables you to assign any type of value (String, Integer, Single, Double, Date etc.) to it. It will automaticaly change the data type when a particular value type is assigned to it.
Dim xyz() as integer/String - Normal type of declaration is like Dim xyz(0 to 11) as Integer (or Dim xyz(1 to 12) - Assume that you want 12 elements in the Array to store 12 month's numbers. So, in this case we know exactly how many elements we need to store data.
Dim xyz() as integer - declares that it is an Array of Integers but doesn't know how many elements are required, in advance. That will be known somewhere in the body of the program.
When we calculate the number of elements then Re-dimension the Array to that maximum(n) number: ReDim xyz(0 to n-1) Integer or ReDim xyz(1 to n) as Integer in the body of the program.
Dim xyz(0) - xyz(0) dimensioned as a variant array with a single element. You need to type three extra characters (0) to access it's contents. This is as good as a single variable xyz (Dim xyz)
Thanks Apr, helpful. I'd always made an array as variant in the past.