|
-
Mar 4th, 2008, 03:44 PM
#1
Thread Starter
New Member
fill array from Combobox
I am currently writing a program which I cant seem to quite finish.. I fill a combobox with multiple lines, consisting of 5 elements delimited by commas. I then am trying to write them separately to a text file which I am using in another program. I think the best way to do that is to store the combobox contents to an array then to a text file.
currently looks like this in the combo box
Bagatelle, Beethoven, Piano Sonata, THIRD, 7
Seven Garden, Motzart, String Symphony, FIFTH, 2
I need it to look like this in the text file
Bagatelle
Beethoven
Piano Sonata
THIRD
7
Seven Garden
Motzart
String Symphony
fifth
2
-
Mar 4th, 2008, 04:52 PM
#2
Re: fill array from Combobox
Welcome to Forums!
Would this work for you?
Code:
Private Sub Command1_Click()
Dim i As Integer
Dim arItems() As String
Dim strOutput As String
For i = 0 To Combo1.ListCount - 1
strOutput = strOutput & Combo1.List(i)
If i < Combo1.ListCount Then
strOutput = strOutput & ","
End If
Next i
arItems = Split(strOutput, ",")
Open "c:\test.txt" For Output As #1
For i = 0 To UBound(arItems)
Print #1, Trim(arItems(i))
Next i
Close #1
MsgBox "File's done."
End Sub
-
Mar 5th, 2008, 10:12 AM
#3
Re: fill array from Combobox
Welcome to the forums. 
May I ask why you are using a single column control like a combo box to store multiple columns? This seems more like a job for a grid control or a Listview control.
-
Mar 5th, 2008, 02:49 PM
#4
Thread Starter
New Member
Re: fill array from Combobox
Listcount is not a member of the combobox, at least not in VB2005, nor is open, Im new to 2005 and am not transitioning well.
-
Mar 5th, 2008, 02:56 PM
#5
Re: fill array from Combobox
 Originally Posted by joshboski
Listcount is not a member of the combobox, at least not in VB2005, nor is open, Im new to 2005 and am not transitioning well.
Moved to VB.NET
-
Mar 5th, 2008, 03:08 PM
#6
Hyperactive Member
Re: fill array from Combobox
this does what you want
Code:
Using sw As IO.StreamWriter = New IO.StreamWriter("c:\Test.txt")
For Each Item As String In ComboBox1.Items
Dim tmp() As String = Item.Split(",")
For Each SplittedString As String In tmp
sw.WriteLine(SplittedString.Trim)
Next
Next
End Using
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
|