How to print the items from ListBox in a specific format
I'm making a windows form modul (from excels visual basic) which has various elements like "Author", "year of publication", "Title" and "Category"
The task is, that after the user given a Value to every of these element theres a button, which saves them into a list, and deletes all the data that has been written into the elements (like the title name category etc)
That was the first part of the main task.
The secont part, is that I have to export the list content into a file, which is not a problem, instead the problem is that I have to export them in a given format!
For example its exports it with my solution like this: (every element is in a new line)
Author name
Books name
Year of publication
Category
Each of the in a new line, but I have to export then in this formation: (every element is in one line, but if I record a new one it should be in a new line like below)
Author name1;Books name1;Year of publication1;Category1;
Author name2;Books name2;Year of publication2;Category2;
I just can't figure it out how to do this!
Here's my code snippet from the export button:
What you have to know about this is :
lista = ListBox1
Code:
Private Sub CommandButton_export_Click()
Dim i As Integer
Open "D:\export.txt" For Append As #1
For i = 0 To lista.ListCount - 2
lista.Selected(i) = True
Print #1, lista.List(lista.ListIndex) & ";"
'lista.List(lista.ListIndex)
Next
Close #1
lista.Clear
End Sub
Re: How to print the items from ListBox in a specific format
Welcome to VBForums :wave:
Thread moved to the 'Office Development/VBA' forum... note that while it certainly isn't made clear, the "VB Editor" in Office programs is actually VBA rather than VB, so the 'VB6' forum is not really apt
Re: How to print the items from ListBox in a specific format
Thanks for the welcome, and sorry for the wrong forum :)
Is there anyone who could help me out? It is very important to me make this little part of the program. I'm not good in visual basic language, but it is vital to me to do this task! Please someone help!
Re: How to print the items from ListBox in a specific format
Quote:
Print #1, lista.List(lista.ListIndex) & ";"
the ; at the end of the line tells it to continue the next print statement on the same line, but you have appended it to the string to be printed
try like
Code:
Print #1, lista.List(lista.ListIndex) ;
1 Attachment(s)
Re: How to print the items from ListBox in a specific format
I've received a solution in another forum, I'm only writing this to others who have, or will have the same problem:
The solution was this:
fileba = ""
For i = 0 To lista.ListCount - 2
lista.Selected(i) = True
fileba = fileba & lista.List(lista.ListIndex) & ";"
Next
Print #1, fileba
It works like a charm! :)
Thanks for the replys!
PS:
Don't bother with the image!