D
Dave B
I'm trying to make my function return an array of strings and can't
seem to get it to work. I get Error 9, subscript out of range. The
error occurs on the line "strArray(i) = str"
Here is the relevant part of the code:
Sub CompareLabels(str1 as String)
Dim strWords1() As String
strWords1 = MakeArrayOfWords(str1)
End Sub
Private Function MakeArrayOfWords(ByVal str As String) As String()
Dim i As Integer, intSpace As Integer, intLength As Integer,
strArray() As String
If str <> "" Then
Do
i = i + 1
intSpace = InStr(1, str, " ", vbTextCompare)
If intSpace > 0 Then
strArray(i) = Left(str, intSpace)
intLength = Len(str) - intSpace
str = Right(str, intLength)
Else
strArray(i) = str
End If
Loop Until intSpace = 0
MakeArrayOfWords = strArray
End If
End Function
Can anyone help? Thanks.
P.S. I suck at working with arrays.
seem to get it to work. I get Error 9, subscript out of range. The
error occurs on the line "strArray(i) = str"
Here is the relevant part of the code:
Sub CompareLabels(str1 as String)
Dim strWords1() As String
strWords1 = MakeArrayOfWords(str1)
End Sub
Private Function MakeArrayOfWords(ByVal str As String) As String()
Dim i As Integer, intSpace As Integer, intLength As Integer,
strArray() As String
If str <> "" Then
Do
i = i + 1
intSpace = InStr(1, str, " ", vbTextCompare)
If intSpace > 0 Then
strArray(i) = Left(str, intSpace)
intLength = Len(str) - intSpace
str = Right(str, intLength)
Else
strArray(i) = str
End If
Loop Until intSpace = 0
MakeArrayOfWords = strArray
End If
End Function
Can anyone help? Thanks.
P.S. I suck at working with arrays.