• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 138
  • Last Modified:

Split help

Sorry everyone, I'm very new to VB6 still. Can someone tell me the difference between:

Split(lblUserID.Caption, ": ")(1)
and
Split(lblUserID.Caption, ": ",1)
0
Takamine334
Asked:
Takamine334
  • 4
  • 3
  • 2
2 Solutions
 
Patrick MatthewsCommented:
>>Split(lblUserID.Caption, ": ")(1)

This returns the second element from the delimited array

>>Split(lblUserID.Caption, ": ",1)

This returns an array of one element, zero-based.

Regards,

Patrick
0
 
PaulHewsCommented:
The first returns the element of the split array at index 1.

The second returns an array of no more than one element.  The optional parameter where the 1 is, indicates that you wish to limit the number of elements returned.

    Dim strSplit() As String
    strSplit = Split("babababababababababababa", "a", 3)
    Dim i As Integer
    For i = 0 To UBound(strSplit)
        Debug.Print strSplit(i)
    Next i

Prints:
b
b
babababababababababa

You can see that the rest of the string makes up the third element.
0
 
PaulHewsCommented:
Patrick  :)
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
Patrick MatthewsCommented:
Paul,

Payback for the one you beat me on earlier :)

Regards,

Patrick
0
 
PaulHewsCommented:
You betcha.  Cheers.  :)
0
 
Patrick MatthewsCommented:
matthewspatrick said:
>>>>Split(lblUserID.Caption, ": ")(1)
>>
>>This returns the second element from the delimited array

Remember, split returns an array, and that array is always zero-based, so index 1 returns
the second element.
0
 
Takamine334Author Commented:
so, what would be the point of doing this:

Split(lblUserID.Caption, ": ",1)

?
0
 
Patrick MatthewsCommented:
Takamine334 said:
>>so, what would be the point of doing this:
>>
>>Split(lblUserID.Caption, ": ",1)

The optional third argument (in this case, 1) limits the number of returned items.  So, let's say
the input string looks like:

1,1,3,w,5,g,h,u,8,99

There are 10 items there.  If I know I only care about, say, the first 5, I can do this:

arr = Split(InputString, ",", 5)

Now arr will be an array with five elements (0 to 4).

If I leave that argument out, I get an array with all 10 elements (0 to 9).
0
 
Takamine334Author Commented:
oh, that makes perfect sense. thank you.
0

Featured Post

Prep for the ITIL® Foundation Certification Exam

December’s Course of the Month is now available! Enroll to learn ITIL® Foundation best practices for delivering IT services effectively and efficiently.

  • 4
  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now