|
-
Apr 15th, 2003, 11:57 PM
#41
Thread Starter
Frenzied Member
From the posts thus far, am I right in understanding that
is a STRING array, and
VB Code:
strArr = Split(arg1, arg2)
is a VARIANT populated with strings and that there is a difference between the two?
If so
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
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.
"Brothers, you asked for it."
...Francisco Domingo Carlos Andres Sebastian D'Anconia
-
Apr 16th, 2003, 01:34 AM
#42
Thread Starter
Frenzied Member
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
"Brothers, you asked for it."
...Francisco Domingo Carlos Andres Sebastian D'Anconia
-
Apr 16th, 2003, 02:48 AM
#43
Thread Starter
Frenzied Member
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.
I missed the above, while reading thro' the thread.
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.
"Brothers, you asked for it."
...Francisco Domingo Carlos Andres Sebastian D'Anconia
-
Apr 16th, 2003, 06:57 AM
#44
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
-
Apr 16th, 2003, 03:59 PM
#45
Stuck in the 80s
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.
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.
-
Apr 17th, 2003, 02:04 AM
#46
Thread Starter
Frenzied Member
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
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
All are vbArray + vbString.
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
VB 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"
results in a Variant Scoped as a String and not a String Array
Am I right in my conclusion?
"Brothers, you asked for it."
...Francisco Domingo Carlos Andres Sebastian D'Anconia
-
Apr 17th, 2003, 02:34 AM
#47
Thread Starter
Frenzied Member
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.
An array of variants with the same datatypes in all its elements
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
"Brothers, you asked for it."
...Francisco Domingo Carlos Andres Sebastian D'Anconia
-
Apr 17th, 2003, 06:12 AM
#48
PowerPoster
Originally posted by KayJay
\
VB 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"
results in a Variant Scoped as a String and not a String Array
Am I right in my conclusion?
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?
-
Apr 17th, 2003, 06:17 AM
#49
Thread Starter
Frenzied Member
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.
"Brothers, you asked for it."
...Francisco Domingo Carlos Andres Sebastian D'Anconia
-
Apr 17th, 2003, 07:37 AM
#50
PowerPoster
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.
I dont understand what you are saying, but debug / run the following code with a watch on strx stry and strz
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)
-
Apr 17th, 2003, 08:08 AM
#51
Thread Starter
Frenzied Member
I did and some.
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
Conclusions:
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?
"Brothers, you asked for it."
...Francisco Domingo Carlos Andres Sebastian D'Anconia
-
Apr 17th, 2003, 08:25 AM
#52
PowerPoster
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
expand strY in the debug watch and you can see each element is scoped to a string
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.
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 string
Ergo, declaring a variable as a variant retains its type and gains a scope depending on the RHS. Agreed.
agreed 
How that does prove that a SPLIT in the RHS generates a Variant with a Scope of Strings on the LHS?
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 ...
-
Apr 17th, 2003, 08:39 AM
#53
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.
-
Apr 17th, 2003, 10:10 AM
#54
Thread Starter
Frenzied Member
Good enough...but
"Brothers, you asked for it."
...Francisco Domingo Carlos Andres Sebastian D'Anconia
-
Apr 17th, 2003, 10:35 AM
#55
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 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.
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
-
Apr 17th, 2003, 04:17 PM
#56
Stuck in the 80s
Anybody have any MS contacts they can call up?
-
Apr 17th, 2003, 07:04 PM
#57
Originally posted by The Hobo
Anybody have any MS contacts they can call up?
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.
-
Apr 17th, 2003, 11:14 PM
#58
I wonder how many charact
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...
-
Apr 17th, 2003, 11:41 PM
#59
Thread Starter
Frenzied Member
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
"Brothers, you asked for it."
...Francisco Domingo Carlos Andres Sebastian D'Anconia
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|