|
-
Aug 1st, 2012, 11:00 AM
#1
Thread Starter
Junior Member
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
-
Aug 1st, 2012, 11:26 AM
#2
Re: How to print the items from ListBox in a specific format
Welcome to VBForums 
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
-
Aug 1st, 2012, 01:52 PM
#3
Thread Starter
Junior Member
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!
Last edited by Gülredy; Aug 1st, 2012 at 02:11 PM.
-
Aug 1st, 2012, 04:28 PM
#4
Re: How to print the items from ListBox in a specific format
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) ;
i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next
dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part
come back and mark your original post as resolved if your problem is fixed
pete
-
Aug 2nd, 2012, 01:41 AM
#5
Thread Starter
Junior Member
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
|