Home All Groups Group Topic Archive Search About
Author
8 May 2006 10:51 AM
Adam Honek
I have the following code below.

The thing is, even if txtCCEmailAddress.Text is empty (no text), CCRecipeant
will return a Ubound() higher than 0 and still go in the loop.

If there's nothing to split how can CCRecipeant be a positive UBound value?
'Get the number of specified CC recipeants

CCRecipeant = txtCCEmailAddress.Text.Split(";")

'Now we need to add each one

For intCounter = 0 To CCRecipeant.GetUpperBound(0)

If CCRecipeant.GetUpperBound(0) >= 0 Then

..........some code here

End If

Next



Thanks,

Adam

Author
8 May 2006 11:01 AM
Fred
Hi,


>From .NET documentation.

Function Split(
   ByVal Expression As String,
   Optional ByVal Delimiter As String = " ",
   Optional ByVal Limit As Integer = -1,
   Optional ByVal Compare As CompareMethod = CompareMethod.Binary
) As String()


If Expression is a zero-length string (""), the Split function returns
an array of length one, containing an empty string.

Can you test txtCCEmailAddress.Text for length first?

Fred
Author
12 May 2006 6:33 AM
Göran_Andersson
Adam Honek wrote:
> I have the following code below.
>
> The thing is, even if txtCCEmailAddress.Text is empty (no text), CCRecipeant
> will return a Ubound() higher than 0 and still go in the loop.

No, it wont. If the string is empty, the array will contain one item, so
UBound will return the value zero. That will make the loop iterate once.

> If there's nothing to split how can CCRecipeant be a positive UBound value?
> 'Get the number of specified CC recipeants

There is always something to split. A string that doesn't contain a
separator contains one item. It doesn't matter if the string is empty or
not.

"asdf;asdf" -> two items: "asdf", "asdf"
"asdf;a" -> two items: "asdf", "a"
"asdf;" -> two items: "asdf", ""

"asdf" -> one item: "asdf"
"a" -> one item: "a"
"" -> one item: ""

Show quoteHide quote
> CCRecipeant = txtCCEmailAddress.Text.Split(";")
>
> 'Now we need to add each one
>
> For intCounter = 0 To CCRecipeant.GetUpperBound(0)
>
> If CCRecipeant.GetUpperBound(0) >= 0 Then
>
> .........some code here
>
> End If
>
> Next