Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Shaun E on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Array problem

Status
Not open for further replies.

MikeMCSD

MIS
Jul 12, 2002
107
US
Dim words() As String = Split(searchString, " ")
Dim wordsCount As Integer = words.Length
Dim index As Integer = 0
Dim addedWords As Integer = 0
Dim holdWords() As String

While addedWords < 5 And index < wordsCount
If Len(words(index)) > 2 Then
addedWords += 1
holdWords(index) = words(index)
End If
index += 1
End While

I get an error when trying to move:
holdWords(index) = words(index)
the contents of one array index into the other,
here is the message:

Object reference not set to an instance of an object.
Line 61: holdWords(index) = words(index)

What am I doing wrong? Thanks
200 points for the answer



 
I did this:
Dim holdWords(4) As String
and it works.

Do arrays have to been initialized or have their
indexes set before you can use them?
Sorry, that question is only worth 50 points.



 
off course you need to initialize them.

but you can also use the arraylist wich you don't need to initialize and works faster then a normal array

Code:
dim ar as new arraylist
ar.add(words(index)

We don't work with points overhere

Christiaan Baes
Belgium

If you want to get an answer read this FAQ faq796-2540
There's no such thing as a winnable war - Sting
 
What you could also do is declare your array without the number of elements, and ReDim it while you are iterating through your loop.
 
thanks . . .

I really don't use arrays often . . . and the books I
have on VB didn't explain them good enough.

I was kidding about the points!

Next, I have to take that array and turn it into a
string with spaces so I can send it over to Full Text Search
"word1 word2 word3" <- like that.
What is an easy way of doing this? For loop? Collection?
 
Yes Mike, there is an easy way to do this...Join.

Code:
Dim strJoinArray as String
strJoinArray = Join(holdWords, " ")

Charles
Quality Assurance/Developer
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top