-
December 19th, 2009, 06:11 PM
#1
help: looping through listbox items to split string
hi experts!
i need some help to develop looping logic as the following:
when have a listbox say "list1" contains some lines of string as items.
actually, i need to loop through these items line by line, and then separate each of them into words.
my try was like this:
-------------------------------------------------------------------
Dim arrWords() As String
Dim i, x As Integer
Text1.Text = ""
For i = 0 To List1.ListCount
For x = 0 To 6
arrWords(x) = Split(Str(List1.List(i)))
If Text1.Text = "" Then
Text1.Text = arrWords(x)
Else
Text1.Text = Text1.Text & vbCrLf & arrWords(x)
End If
Next x
Next i
----------------------------------------------------------------------
any help would be highlly appreciated.. thnx in advance
-
December 19th, 2009, 06:57 PM
#2
Re: help: looping through listbox items to split string
Please use CODE TAGS around your code
What is the error message you're getting?
-
December 20th, 2009, 07:28 AM
#3
Re: help: looping through listbox items to split string
oh sorry, here is the code again:
Code:
Dim arrWords() As String
Dim i, x As Integer
Text1.Text = ""
For i = 0 To List1.ListCount
For x = 0 To List1.ListCount
arrWords(x) = Split(Str(List1.List(i)))
If Text1.Text = "" Then
Text1.Text = arrWords(x)
Else
Text1.Text = Text1.Text & vbCrLf & arrWords(x)
End If
Next x
Next i
and the error massege is "Run-time error '13': Type mismatch"
thanks
-
December 20th, 2009, 08:23 AM
#4
Re: help: looping through listbox items to split string
On which line do you get the error code?
-
December 20th, 2009, 09:13 AM
#5
Re: help: looping through listbox items to split string
on this line:
Code:
arrWords(x) = Split(Str(List1.List(i)))
thanks
-
December 20th, 2009, 11:31 AM
#6
Re: help: looping through listbox items to split string
hi guys
i am here again just to tell you that i got over the problem by using vb9, ".net" with code like the following structure:
"it may helps someone else"
Code:
Dim i As Integer
For i = 0 To ListBox1.Items.Count - 1
Dim arrWords() As String = ListBox1.Items(i).Split(" ")
For x = 0 To UBound(arrWords)
ListBox2.Items.Add(arrWords.ElementAt(x))
Next x
Next i
so many thanks for all of you.
-
December 20th, 2009, 02:32 PM
#7
Re: help: looping through listbox items to split string
Maybe this is good for nothing at this point anymore, but:
I'd like to point out that the very same could have been achieved in VB6, too.
Code:
Dim i As Integer
Dim arrWords() as String
For i = 0 To ListBox1.Items.Count - 1
arrWords = Split(ListBox1.Items(i), " ")
For x = 0 To UBound(arrWords)
ListBox2.AddItem arrWords(x)
Next x
Next i
I think the previous type mismatch lied in this instruction: Split(Str(List1.List(i)))
The list elements are already strings, so using the Str() function is obsolete and produces the error: it expects anumeric argument.
-
December 20th, 2009, 04:19 PM
#8
Re: help: looping through listbox items to split string
yup, you are totally right..
it works Smoothly too
thanks a lot.
-
April 14th, 2018, 03:41 PM
#9
Re: help: looping through listbox items to split string
thank you so much !! it did help me!!
-
April 14th, 2018, 03:42 PM
#10
Re: help: looping through listbox items to split string
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|