Re: Ubound behavior with Split vs. ReDim
From: Rick Rothstein (rickNOSPAMnews_at_NOSPAMcomcast.net)
Date: 08/29/04
- Next message: Hal Rosser: "Re: Validating 1st Date is Before 2nd Date"
- Previous message: Randy Birch: "Re: How can another program use a procedure/function in mine?"
- In reply to: Mike Schumann: "Ubound behavior with Split vs. ReDim"
- Next in thread: Ulrich Korndoerfer: "Re: Ubound behavior with Split vs. ReDim"
- Messages sorted by: [ date ] [ thread ]
Date: Sat, 28 Aug 2004 21:04:09 -0400
> I have a perplexing problem in Visual Basic 6.0.
>
> I am trying to implement a Parse function that is similar to Split,
but
> which treats string elements delimited by quotes as a single item, so
that I
> can parse command lines properly.
>
> The following statement evaluates to -1:
>
> i = UBound(Split(""))
>
> The following code results in an error (Subscript out of Range):
>
> Dim Array() as String
> i = Ubound(Array)
>
> The only way that I can get Ubound to work is if I first use ReDim to
size
> my array.
>
> How can I set up a ReDim array to have no entries, as is the case with
the
> Split function?
>
> Note: It seems that I can create the same behavior if I execute the
> following statement:
>
> Dim Array() as String
> Array = Split("")
You can use the Erase statement to clear a dynamic array. I would
suggest you choose a different name for your array variable as Array is
the name of a built-in function in VB6. As for Split'ting strings where
the delimiter appears inside quote marks, you may find this function
I've posted in the past to be useful.
Function SplitAroundQuotes(TextToSplit As String, _
Optional Delimiter As String = ",") As String()
Dim QuoteDelimited() As String
Dim WorkingArray() As String
QuoteDelimited = Split(TextToSplit, """")
For X = 1 To UBound(QuoteDelimited) Step 2
QuoteDelimited(X) = Replace$(QuoteDelimited(X), _
Delimiter, Chr$(0))
Next
TextToSplit = Join(QuoteDelimited, """")
TextToSplit = Replace$(TextToSplit, Delimiter, Chr$(1))
TextToSplit = Replace$(TextToSplit, Chr$(0), Delimiter)
WorkingArray = Split(TextToSplit, Chr$(1))
SplitAroundQuotes = WorkingArray
End Function
Rick - MVP
- Next message: Hal Rosser: "Re: Validating 1st Date is Before 2nd Date"
- Previous message: Randy Birch: "Re: How can another program use a procedure/function in mine?"
- In reply to: Mike Schumann: "Ubound behavior with Split vs. ReDim"
- Next in thread: Ulrich Korndoerfer: "Re: Ubound behavior with Split vs. ReDim"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|