Uncomment and U get a Ubound of -1. So what does SPLIT do to the array?VB Code:
Private Sub Command1_Click() Dim strT As String, strX() As String 'strX = Split(strT) MsgBox UBound(strX) End Sub
Uncomment and U get a Ubound of -1. So what does SPLIT do to the array?VB Code:
Private Sub Command1_Click() Dim strT As String, strX() As String 'strX = Split(strT) MsgBox UBound(strX) End Sub
Split returns a String array. Its documented somewhere in the help that when Split and Filter return empty arrays, the LBound is 0, while the UBound is -1. They do that as a means of error checking without raising an actual error.
Try putting something into the string then read the ubound
String array. Plain and simple.
VB Code:
Private Sub Form_Load() Dim x As String: x = "a,b,c" '' returns String() '' MsgBox TypeName(Split(x, ",")) '' returns 'a' '' MsgBox Split(x, ",")(0) End Sub
... never heard of Filter(). Do you have a sample by any chance ?Quote:
Originally posted by crptcblade
Split returns a String array. Its documented somewhere in the help that when Split and Filter return empty arrays, the LBound is 0, while the UBound is -1. They do that as a means of error checking without raising an actual error.
Actually found a vbs sample
VB Code:
dim a(5),b a(0)="Saturday" a(1)="Sunday" a(2)="Monday" a(3)="Tuesday" a(4)="Wednesday" b=Filter(a,"n") document.write(b(0) & "<br />") document.write(b(1) & "<br />") document.write(b(2)) Output:Sunday Monday Wednesday
Looks handy!
The reason I asked was when an empty String Array's Ubound is sought, a list index error occurs; but when an empty string is split, the result is the same empty string array, which does not errror out. Or is it the same?
:)
String and Filter return an initialized array, just initialized as empty. It sounds the same, but its quite different than an uninitialized array.
I would have to argue with you on this.Quote:
Originally posted by plenderj
String array. Plain and simple.
VB Code:
Private Sub Form_Load() Dim x As String: x = "a,b,c" '' returns String() '' MsgBox TypeName(Split(x, ",")) '' returns 'a' '' MsgBox Split(x, ",")(0) End Sub
If Split() were to return a variant, your first MessageBox would give you "String" anyways. Try this code:
VB Code:
Dim vVar As Variant vVar = 5 MsgBox TypeName(vVar) vVar = "cool" MsgBox TypeName(vVar)
So just because TypeName() gives you string after a Split() function doesn't prove that it's a String array. If it's Variant, it will tell you whatever the contents of the variable are.
And, if you look in the Object Explorer, for Split(), you see:
Other functions, such as Left read the same way, except Left$ reads:Quote:
Function Split(Expression As String, [Delimiter], [Limit As Long = -1], [Compare As VbCompareMethod = vbBinaryCompare])
So I have to argue with you and say that Split() returns a variant.Quote:
Function Left$(String As String, Length As Long) [b]As String[b]
Maybe the following piece of code using the Split function could help:
Private Sub Command1_Click()
Dim str As String
Dim vElements As Variant
Dim vElement As Variant
str = "a,b,c,d,e,f"
vElements = Split(str, ",")
For Each vElement In vElements
Debug.Print vElement
Next
End Sub
I'm still going with strings as the element types in split. From MSDN:
andQuote:
Returns a zero-based, one-dimensional array containing a specified number of substrings.
Quote:
delimiter - Optional. String character used to identify substring limits. If omitted, the space character (" ") is assumed to be the delimiter. If delimiter is a zero-length string, a single-element array containing the entire expression string is returned.
I am pretty sure it returns a string. try these to see what I mean:
VB Code:
Private Sub Command1_Click() 'THIS RUNS Dim arr() As String arr() = Split("a-1-e-234-1.11", "-") End Sub
VB Code:
Private Sub Command1_Click() 'THIS CRASHES Dim arr() As Variant arr() = Split("a-1-e-234-1.11", "-") End Sub
No where does that state that an array of strings is returned. Just that the elements are strings. And variants can hold any data type, including strings.Quote:
Originally posted by VBGuy
I'm still going with strings as the element types in split. From MSDN:
and
Quote:
Originally posted by Muddy
I am pretty sure it returns a string. try these to see what I mean:
VB Code:
Private Sub Command1_Click() 'THIS RUNS Dim arr() As String arr() = Split("a-1-e-234-1.11", "-") End Sub
VB Code:
Private Sub Command1_Click() 'THIS CRASHES Dim arr() As Variant arr() = Split("a-1-e-234-1.11", "-") End Sub
VB Code:
Private Sub Command1_Click() Dim arr As Variant arr = Split("a-1-e-234-1.11", "-") End Sub
Well since Split works in VB.net and VB.net does not have Variants i would assume it returns a string.
They key is in how the array is decalred.... in the orignal post, it was dim as an array of Strings... that's why split reurns a type of string.... I've also used it to split numbers into an array of variants (an array of longs didn't work... not sur why though)Quote:
Originally posted by The Hobo
No where does that state that an array of strings is returned. Just that the elements are strings. And variants can hold any data type, including strings.
VB Code:
Private Sub Command1_Click() Dim arr As Variant arr = Split("a-1-e-234-1.11", "-") End Sub
Also what would be the point of using variants? THe Input is a string, there is no reason ot use a variant...you can't input an Integer or Long etc.. only strings, therefore only a string array would ever be needed.
As pointless as this discussion is :D ...
I have to believe that this would work if Split returned a Variant (it doesnt work):
VB Code:
Private Sub Command1_Click() Dim arr() As Variant arr = Split("a-1-e-234-1.11", "-") End Sub
Uh, sure there is..... real-world example... I have a grid... I store the col headers in a string that I can split out and use to set the headres, at the same time, I have a secondary string that contains 0's and 1' that indicate if the col is to be shown or not. Since the Split can return a variant, I don't have to worry about CLng'ng the array element.... it's ready fopr me to use as is.Quote:
Originally posted by Arc
Also what would be the point of using variants? THe Input is a string, there is no reason ot use a variant...you can't input an Integer or Long etc.. only strings, therefore only a string array would ever be needed.
You're making it sound like the split would return the numbers as Variant/Integer ... and it won't (I'm pretty sure anyway). When splitting to a Variant "Splits in" a Variant/String array. So if you are in the habit of Clng your Strings, you'd still find the same need to Clng your Variant/Strings would you not?Quote:
Originally posted by techgnome
Uh, sure there is..... real-world example... I have a grid... I store the col headers in a string that I can split out and use to set the headres, at the same time, I have a secondary string that contains 0's and 1' that indicate if the col is to be shown or not. Since the Split can return a variant, I don't have to worry about CLng'ng the array element.... it's ready fopr me to use as is.
From the horse's mouth:
Quote:
Microsoft Office 2000/Visual Basic Programmer's Guide
--------------------------------------------------------------------------------
The Split Function
The Split function takes a string and converts it into an array of strings. By default, it divides the string into elements by using the space character as a delimiter, so that if you pass in a sentence, each element of the array contains a word. For example, if you pass this string to the Split function
...
Uhh well it's up to you to convert the string into a lng etc.. It would be stupid for Microsoft to use a Variant in a Function that only accepts strings.. If they wanted to return a Variant they would allow you to input a variant as the value IMHO!:DQuote:
Originally posted by techgnome
Uh, sure there is..... real-world example... I have a grid... I store the col headers in a string that I can split out and use to set the headres, at the same time, I have a secondary string that contains 0's and 1' that indicate if the col is to be shown or not. Since the Split can return a variant, I don't have to worry about CLng'ng the array element.... it's ready fopr me to use as is.
For Example :
Function Split(Item as Variant, Delimiter as Variant) as Variant
That way you could input a Number or a string, which is the only reason to ever use a variant.
A=Split(123.45,.)
This would return 123 and 45
Split returns a Variant array scoped as a string array, same as Mid, Left, Right returns a variant scoped as a string (however with those functions you can use Mid$, Left$, Right$ to return a string).
That this doesn't work:Is because the variant is declared in the wrong way the code should look like this:VB Code:
Dim v() As Variant v = Split("x-y-z", "-")In other words no paranthesis in the declaration.VB Code:
Dim v As Variant v = Split("x-y-z", "-")
The fact that VB.Net also has a Split method has nothing to do with the VB6 Split function, the implementation is different.
The reason it returns a variant array is because Split existed in VBScript before it was introduced in VB6.
However this discussion is purely academic since it doesn't really matter.
I don't see where the confusion comes from. According to help,Since all elements of an array are the same type, and the above says the elements are strings, doesn't that mean it returns a string array?Quote:
Split Function
Returns a zero-based, one-dimensional array containing a specified number of substrings
As I said this discussion is purely academic.... The fact that it returns an array of substrings doesn't contradict the fact that it actually returns a variant array scoped as strings.Quote:
Originally posted by seaweed
I don't see where the confusion comes from. According to help,Since all elements of an array are the same type, and the above says the elements are strings, doesn't that mean it returns a string array?
Dim v() as Variant isn't "wrong"Quote:
Originally posted by Joacim Andersson
Split returns a Variant array scoped as a string array, same as Mid, Left, Right returns a variant scoped as a string (however with those functions you can use Mid$, Left$, Right$ to return a string).
That this doesn't work:Is because the variant is declared in the wrong way the code should look like this:VB Code:
Dim v() As Variant v = Split("x-y-z", "-")In other words no paranthesis in the declaration.VB Code:
Dim v As Variant v = Split("x-y-z", "-")
The fact that VB.Net also has a Split method has nothing to do with the VB6 Split function, the implementation is different.
The reason it returns a variant array is because Split existed in VBScript before it was introduced in VB6.
However this discussion is purely academic since it doesn't really matter.
in the example with v() you are creating a variant array
in the example with v you are creating an variant that is later used to hold a string array
just out of curiosity is there a reference that says Split returns a Variant/String?
By the way, I agree that the argument is purely academic ... Im just hanging around out of curiosity ... and am still convinced Split returns a String ... :D
I already regret I even started to participate in this discussion :)
Anyway I hope you agree that it defiantly not return a string, if anything a string array is not a string even if it might just contain one string ;)
Joacim, I know you know your stuff from seeing previous posts. That said, the fact that I cant understand a single word of what you just typed must mean that I am way out of my league ... so Ill just bow out while I am ahead ... :DQuote:
Originally posted by Joacim Andersson
I already regret I even started to participate in this discussion :)
Anyway I hope you agree that it defiantly not return a string, if anything a string array is not a string even if it might just contain one string ;)
I'll just have to remain unconvinced by reason of my own ignorance :D
Cheers!
Well the truth is it's not academic... if Split returns a Variant(which it doesnt) then memory is being wasted for no reason since it can only accept strings!:D It would make more sense to create your own Split Function that used a string array in order to save memory.
Here is undeniable proff that Split returns a string.
VB Code:
Dim I As Integer Dim A As Variant A = Split("Test,test,test", ",") I = A(1)
You can't say I=A(1) becasue it is a string and you get a type mismatch error. If it were a Variant it wouldnt be a problem :)
not a good test IMHO ... try this
VB Code:
Private Sub Command1_Click() Dim i As Integer Dim s As String Dim a As Variant a = "11" s = "11" i = a MsgBox i i = s MsgBox i s = Split("11", "-") MsgBox s i = Split("11", "-") MsgBox i End Sub
now check this reference that supports Split returns Variant
http://support.microsoft.com/default...en-us%3B188007
then again , Ive seen blatant errors in the msdn kb before
Quote:
Originally posted by Muddy
not a good test IMHO ... try this
VB Code:
Private Sub Command1_Click() Dim i As Integer Dim s As String Dim a As Variant a = "11" s = "11" i = a MsgBox i i = s MsgBox i s = Split("11", "-") MsgBox s i = Split("11", "-") MsgBox i End Sub
now check this reference that supports Split returns Variant
http://support.microsoft.com/default...en-us%3B188007
then again , Ive seen blatant errors in the msdn kb before
Uhh if it returned a Variant you wouldnt get a type mismatch error in the code i provided... pretty simple stuff.
An assumption is far from fact.Quote:
Originally posted by Arc
Well since Split works in VB.net and VB.net does not have Variants i would assume it returns a string.
Any array of strings does not mean a string array. A variant can be an array of strings.Quote:
Originally posted by Muddy
From the horse's mouth:
The Split function takes a string and converts it into an array of strings.
Don't make me kick the horse in the mouth. ;)
No. According to what you posted, it is an array of substrings. Variants can be an array of substrings.Quote:
Originally posted by seaweed
Since all elements of an array are the same type, and the above says the elements are strings, doesn't that mean it returns a string array?
you are right of course if your saying my code was pointless ... I went brain dead (not uncommon for me)Quote:
Originally posted by Arc
Uhh if it returned a Variant you wouldnt get a type mismatch error in the code i provided... pretty simple stuff.
still not sure what point your test makes though ...
I give up ... :D
Maybe some machine language guru will dig into it and give a qualified answer ...
What I meant is that a string array is an array of strings. An array is not the same as a string. Split doesn't return a string.Quote:
Originally posted by Muddy
Joacim, I know you know your stuff from seeing previous posts. That said, the fact that I cant understand a single word of what you just typed must mean that I am way out of my league ... so Ill just bow out while I am ahead ... :D
I'll just have to remain unconvinced by reason of my own ignorance :D
Cheers!
Yupp, you can't assign a string to an integer unless the string contains a value that can be converted to an integer which this doesn't. A(1) is a Variant since you have declared it as such but it contains a string not an integer.Quote:
Originally posted by Arc
Here is undeniable proff that Split returns a string.
VB Code:
Dim I As Integer Dim A As Variant A = Split("Test,test,test", ",") I = A(1)
You can't say I=A(1) becasue it is a string and you get a type mismatch error. If it were a Variant it wouldnt be a problem :)
Can everyone agree that the Left and Right functions returns a substring? Yes it does! But the return value is a variant scoped as a string. If you want them to return a string you must use the Left$ and Right$ functions instead. The same goes for a bunch of other functions such as the Format, Mid, and Str functions.
Just run an application in MS debugger (or any other debugger) and watch the call stack just before the Split function returns and you'll see the memory usage for the return value is larger than the memory used by the string array receiving the return value (if that is declared as a String array that is).
Now I see your point .. and I do agree (even though I dont see the relevance to the topic.Quote:
Originally posted by Joacim Andersson
What I meant is that a string array is an array of strings. An array is not the same as a string. Split doesn't return a string.
That experiment you did with the debugger is convincing though ...
The relevancy is that you said that Split returned a string :)... Nevermind though, it was meant as a joke...Quote:
Originally posted by Muddy
... and am still convinced Split returns a String ... :D
Busted .... yeah that was mispoken.Quote:
Originally posted by Joacim Andersson
The relevancy is that you said that Split returned a string :)... Nevermind though, it was meant as a joke...
Thanks for letting me pick your brain on a pointless yet curiously addictive topic. :D
From the posts thus far, am I right in understanding that
is a STRING array, andVB Code:
dim strArr() as String
is a VARIANT populated with strings and that there is a difference between the two?VB Code:
strArr = Split(arg1, arg2)
If so
does not show any other result other than STRING() and/or STRING for the variables. Using VarType gives the undifferentiable result of 8200 for both as well, though I am not able to deciphet that result.VB Code:
Private Sub Command1_Click() Dim strT As String Dim varT As Variant Dim strX() As String Dim varX As Variant strT = "A-TEST-FOR-FINDING-OUT-WHAT-SPLIT-DOES" varT = "A-TEST-FOR-FINDING-OUT-WHAT-SPLIT-DOES" MsgBox TypeName(strT) MsgBox TypeName(varT) strT = varT MsgBox TypeName(strT) strT = "A-TEST-FOR-FINDING-OUT-WHAT-SPLIT-DOES" varT = strT MsgBox TypeName(varT) strX = Split(strT, "-") varX = Split(varT, "-") MsgBox TypeName(strX) MsgBox TypeName(varX) strX = varX MsgBox TypeName(strX) strX = Split(strT, "-") varX = strX MsgBox TypeName(varX) ReDim strX(12) As String strX(0) = "W" strX(1) = "H" strX(2) = "A" strX(3) = "T" strX(4) = " " strX(5) = "I" strX(6) = "S" strX(7) = " " strX(8) = "T" strX(9) = "H" strX(10) = "I" strX(11) = "S" strX(12) = "?" MsgBox TypeName(strX) strX = varX MsgBox TypeName(varX) End Sub
Is this proof that SPLIT has everything to do with STRINGS and nothing to do with VARIANTS?
VB Code:
Private Sub Command1_Click() 'VarType 8192 is VbArray 'VarType 3 is Long 'VarType 8 is String 'VarType 12 is Variant On Error Resume Next Dim x() As Long, y() As String Dim z() As Variant, xyz As Variant MsgBox varType(x) & _ vbCrLf & _ varType(y) & _ vbCrLf & _ varType(z) & _ vbCrLf & _ varType(xyz) 'X is 8195 --> 8192 + 3 'Y is 8200 --> 8192 + 8 'Z is 8204 --> 8192 + 12 'XYZ is 0 --> Empty x = Split("1-2-3-4", "-") 'Type mismatch y = Split("1-2-3-4", "-") z = Split("1-2-3-4", "-") 'Type Mismatch xyz = Split("1-2-3-4", "-") MsgBox varType(x) & _ vbCrLf & _ varType(y) & _ vbCrLf & _ varType(z) & _ vbCrLf & _ varType(xyz) 'Now the results are 'X is 8195 --> 8192 + 3 'Take a look at the next line and 'Y is 8200 --> 8192 + 8 'Z is 8204 --> 8192 + 12 'the one after this 'XYZ is 8200 --> 8192 + 8 'Split returns a vbArray of Strings 'not a vbArray of variants 'Meaning a vbArray is different from a vbVariant End Sub
I missed the above, while reading thro' the thread.Quote:
Originally posted by Joacim Andersson
.......
The reason it returns a variant array is because Split existed in VBScript before it was introduced in VB6.
However this discussion is purely academic since it doesn't really matter.
:D :p
A word of warning: Don't you ever say "..academic since it doesn't really matter" anywhere within my earshot (or eyesight). I come from a family (within 2 generations and only once removed) of proffessors, school principals, teachers, college lecturers, authors, philosophers, language scholars and of course my pa is a lawyer. Acedemics is perhaps the only thing that matters.
:D :p
Using VarType doesn't prove anything else than the data is a string. A variant can hold a string and if it does the return value for VarType is vbString. The only time VarType returns vbVariant is when when you have an array of Variants. An array of variants is not the same as a variant array scoped as string. An array of variants is an array of different types of data, a string, an integer, a single and so on.
If you assign a variant array of strings to a string array you don't have anything else but a string array. Again I suggest to anyone to step through a VB EXE, that uses the Split function, through a binary debugger and watch the stack just before Split returns and you will see that the memory used for the array is the equal of manually setting up the same string array in variants.
I didn't mean to offend anyone by saying "academic" and "doesn't matter" in the same sentence :) But in my opinion it still doesn't matter how VB internally treat the return value of the function. Of course if it would have used pure VB strings it would have been slightly faster and less memory would be consumed while the function is running. But I don't care, memory is released as soon as the call fall out of scope anyway. The importent thing is not to assign the return value to a variant. However even if I don't think the return type is important this is still an academic discussion (of no larger importance). Everything doesn't become important just because it's academic you know :)
using TypeName doesn't prove anything, hence:Quote:
Originally posted by KayJay
does not show any other result other than STRING() and/or STRING for the variables. Using VarType gives the undifferentiable result of 8200 for both as well, though I am not able to deciphet that result.
VB Code:
Private Sub Form_Load() Dim VarType As Variant VarType = 42 MsgBox TypeName(VarType) 'Integer VarType = "This is a string in a variant." MsgBox TypeName(VarType) 'String End Sub
Never returns variant, yet your datatypes are variant.
I still have not see any proof that it returns a String(), and have seen hard evidence that it returns a Variant.
JA: I was asking whether vbArray is a different type of variable that vbVariant. The object browser says so. Not withstanding the fact that I am currently unable to debug the way you suggested, the second set of code I posted (using VarType) results in something as below
All are vbArray + vbString.VB Code:
Private Sub Command1_Click() Dim strX() As String Dim strY() As String Dim varX As Variant ReDim strX(4) As String strX(0) = "A" strX(1) = "B" strX(2) = "C" strX(3) = "D" strX(4) = "E" strY = Split("A-B-C-D-E", "-", -1, vbBinaryCompare) varX = Split("A-B-C-D-E", "-", -1, vbBinaryCompare) MsgBox VarType(strX) _ & vbCrLf & _ VarType(strY) _ & vbCrLf & _ VarType(varX) End Sub
If what U say is true and proven, i.e. Split results in a Variant Scoped as a String and not a String Array, the above code leads me to conclude that there is no such thing as a string array at all in VB. Even
results in a Variant Scoped as a String and not a String ArrayVB Code:
Dim strX() As String ReDim strX(4) As String strX(0) = "A" strX(1) = "B" strX(2) = "C" strX(3) = "D" strX(4) = "E"
Am I right in my conclusion?
An array of variants with the same datatypes in all its elementsQuote:
Originally posted by The Hobo
using TypeName doesn't prove anything, hence:
VB Code:
Private Sub Form_Load() Dim VarType As Variant VarType = 42 MsgBox TypeName(VarType) 'Integer VarType = "This is a string in a variant." MsgBox TypeName(VarType) 'String End Sub
Never returns variant, yet your datatypes are variant.
I still have not see any proof that it returns a String(), and have seen hard evidence that it returns a Variant.
VB Code:
Private Sub Command1_Click() Dim varX() As Variant, varY As Variant ReDim varX(4) As Variant varX(0) = CStr("A") varX(1) = CStr("B") varX(2) = CStr("C") varX(3) = CStr("D") varX(4) = CStr("E") MsgBox VarType(varX) '8192 + 12 = 8204 --> An array of variants varY = varX() MsgBox VarType(varY) '8192 + 12 = 8204 --> An array of variants varY = Split("A,B,C,D,E", ",", -1, vbBinaryCompare) MsgBox VarType(varY) '8192 + 8 = 8200 --> An array of strings End Sub
THis would result in a String array ... what led you to the conclusion that it was a variant scoped as a string in this case?Quote:
Originally posted by KayJay
\
results in a Variant Scoped as a String and not a String ArrayVB Code:
Dim strX() As String ReDim strX(4) As String strX(0) = "A" strX(1) = "B" strX(2) = "C" strX(3) = "D" strX(4) = "E"
Am I right in my conclusion?
Muddy, because VarType VBARRAY plus VarType VBSTRING is the result of both a hard coded array of strings and the result of a SPLIT() function. Hence if SPLIT() results in Variant Scoped as a String, then so should a hard code array of strings.
I dont understand what you are saying, but debug / run the following code with a watch on strx stry and strzQuote:
Originally posted by KayJay
Muddy, because VarType VBARRAY plus VarType VBSTRING is the result of both a hard coded array of strings and the result of a SPLIT() function. Hence if SPLIT() results in Variant Scoped as a String, then so should a hard code array of strings.
VB Code:
Private Sub Command1_Click() Dim strX() As String Dim strY() As Variant Dim strZ As Variant ReDim strX(1) ReDim strY(1) strX(0) = "A" strX(1) = "B" strY(0) = "A" strY(1) = "B" strZ = strX End Sub
now look at the var types in the watch window. It shows that:
strx is a string array
stry is a variant array with each element scoped to a string
strz is a variant (NOT a variant array) that is scoped as a string array
Split seems to return the the third example (a variant scoped as a string array)
I did and some.
Conclusions:VB Code:
Private Sub Command1_Click() Dim strX() As String Dim strY() As Variant Dim strZ As Variant Dim strXYZ() As String Dim varXYZ As Variant ReDim strX(1) ReDim strY(1) strX(0) = "A" strX(1) = "B" strY(0) = "A" strY(1) = "B" strZ = strX strXYZ = Split("a,b,c,d", ",") varXYZ = Split("a,b,c,d", ",") varXYZ = 10 End Sub
1) strY is not a variant array with each element scoped to a string. It is Variant/Variant(0 to 1). Scoped to a varaint, not a string
2) strZ, I agree with you.
3) strXYZ, the result of a Split, is String(0 to 1). That is not a Variant with a scope of String. Just a String Array.
4) varXYZ , when assigned to a Split, does retain its vartype of Variant and gains a scope of String. It retains its type and gains a scope of an Integer as well.
Ergo, declaring a variable as a variant retains its type and gains a scope depending on the RHS. Agreed.
How that does prove that a SPLIT in the RHS generates a Variant with a Scope of Strings on the LHS?
:confused:
expand strY in the debug watch and you can see each element is scoped to a stringQuote:
1) strY is not a variant array with each element scoped to a string. It is Variant/Variant(0 to 1). Scoped to a varaint, not a string
i agree that strXYZ is a string array but that doesnt mean that split returns a String ... You could assign the contents of any variable type to a string and it would be coerced to stringQuote:
3) strXYZ, the result of a Split, is String(0 to 1). That is not a Variant with a scope of String. Just a String Array.
agreed :)Quote:
Ergo, declaring a variable as a variant retains its type and gains a scope depending on the RHS. Agreed.
I dont think any of this proves it one way or another. I can say the Jaocim's test (stack size in assembly debugger) was a convincing argument that Split returns a variant ...Quote:
How that does prove that a SPLIT in the RHS generates a Variant with a Scope of Strings on the LHS?
Although I don't understand the importance of the discussion, I would come to the conclusion that Split returns a variant, just by the defination i see in the object browser:
Function Split(Expression As String, [Delimiter], [Limit As Long = -1], [Compare As VbCompareMethod = vbBinaryCompare])
No return type is specified, which means it returns a variant.
Good enough...but :D
VB of course have string arrays. When a variant is "scoped" as a type it only means that it has been assigned a value of a specific type. You can with a variant change the type though by assigning a new type of value to it. With an Integer you can't assign a string, right? But if you have assigned a string to a variant it is now scoped as a string which means you can't now assign that value to an integer, however you can still assign an Integer to the variant variable, which is then scoped as an Integer.Quote:
Originally posted by KayJay
Muddy, because VarType VBARRAY plus VarType VBSTRING is the result of both a hard coded array of strings and the result of a SPLIT() function. Hence if SPLIT() results in Variant Scoped as a String, then so should a hard code array of strings.
A variable declared as a string is always scoped as a string and can't be changed (even though an Integer can always be converted to a string the opposit is not always possible).
What the VarType function does is to returned the scoped value. So the VarType of a string is always returned as vbString no matter what variable type it is that holds the string (there's only two types that can hold a string: String and Variant).
See the following example:VB Code:
Dim v As Variant 'check the VarType of v before we have assigned a value Debug.Print VarType(v) 'returns vbEmpty v = "Hello World" ' "Hello World" is a string constant Debug.Print VarType(v) 'returns vbString since v now contains a string v = 25 ' 25 is an Integer constant Debug.Print VarType(v) 'returns vbInteger since v now contains an Integer v = "75" ' "75" is a STRING constant but can be converted to an Integer Debug.Print VarType(v) 'Even though 75 is an Integer value, "75" is not, returns vbString
Anybody have any MS contacts they can call up? :D
Why, my tests with a debugger clearly shows that Split returns a variant, and as Frans C mentioned, the Object Browser also shows that. However if you assign the return value to a String array, you've got a string array and nothiing else.Quote:
Originally posted by The Hobo
Anybody have any MS contacts they can call up? :D
Well, maybe a test would involve passing the return value to a C++ Dll that only accepted an array of characters.... but that would be complicated... perhaps an API (lol) that accepts an array of strings.... (which probably wouldn't work either since the VB compiler would probably implicity cast them)....
Anyway, for the record, I believe the return type is variant for .... String Arrays are not a primitive type... while a Variant is...
Ok.
1) A RHS with a Split() returns a Variant scoped with Strings, in memory, before assigning a value to LHS.
2) If LHS is a String() then LHS remains a String()
3) If LHS is Varaint then LHS becomes a Variant scoped with Strings
4) VarType returns the current Scope of the its Argument
5) So does VarName
6) Thank You
Regards
KayJay
:) ;)