|
-
May 28th, 2009, 03:51 PM
#1
Thread Starter
Junior Member
[RESOLVED] Print data from a ListBox (?)
Hi there. I was just wondering if there was a way for me to copy each item in a ListBox to a TextBox.
I am making a Pin Number Generator Application and all the Pin numbers get added into a ListBox.
I want to copy all the data in the ListBox into a TextBox. Prefferibly one pin on a line in the TextBox.
This is so I could save all of the pin numbers into a text file.
The TextBox will be called txtBox and the ListBox is called lstPass.
Thanks to those who can help me. Also i would be greatful if you could comment the code.
Thanks in advanced.
Alistair.
-
May 28th, 2009, 03:54 PM
#2
Re: Print data from a ListBox (?)
The above is pretty simple. Maybe you should show us what you have tried. A vast majority of the people here can help on this one.
-
May 28th, 2009, 04:02 PM
#3
Hyperactive Member
Re: Print data from a ListBox (?)
i think you wanna put all list items finaly in a text file, right
here's d code
Code:
Dim i As Integer
Dim fileNum As Integer
fileNum = FreeFile()
Open "C:\" & "\list.txt" For Output As #fileNum
For i = 0 To List1.ListCount - 1
Print #fileNum, List1.List(i)
Next i
Close #fileNum
put this code into a command button or something...
hope it will work
Do reply
-
May 28th, 2009, 04:02 PM
#4
Thread Starter
Junior Member
Re: Print data from a ListBox (?)
Thanks LaVolpe. I have not tried anything because i have no idea how to do it.
1) I have a commmand button that generates the passwords and populates the listbox.
I want to add an another command button to add all of the items in the listbox into a textbox so i can save them to a text file.
I don't know if there is a way of copying everything from the listbox into a file without a textbox.
Thanks.
Alistair.
-
May 28th, 2009, 04:04 PM
#5
Hyperactive Member
Re: Print data from a ListBox (?)
Have u read my reply!!!!!!\
-
May 28th, 2009, 04:04 PM
#6
Thread Starter
Junior Member
Re: Print data from a ListBox (?)
Thanks Jimq. Do i need to put:
Dim i As Integer
Dim fileNum As Integer
Into the General Declerations or the CommandButton Sub? Or does it not really matter?
-
May 28th, 2009, 04:06 PM
#7
Hyperactive Member
Re: Print data from a ListBox (?)
-
May 28th, 2009, 04:10 PM
#8
Thread Starter
Junior Member
Re: Print data from a ListBox (?)
Jimq: Does the file need to be made first before it can get saved?
Sorry i'm a bit silly!
-
May 28th, 2009, 04:11 PM
#9
Re: Print data from a ListBox (?)
Design a form with two command buttons, a list box and a text box. Set the MultiLine property of the textbox to True and and add a vertical scrollbar. Then apply this code:
Code:
Const ListSize = 20
Private Sub Command1_Click()
' Write List Box Contents to File and to Text Box
Open "MyDataFile" For Output As #1
For I = 1 To List1.ListCount
Text1.Text = Text1.Text & List1.List(I - 1) & vbCrLf
Print #1, List1.List(I - 1)
Next
Close
End Sub
Private Sub Command2_Click()
' Read File and Build List Box with Contents
Dim MyData As String, ArrItem() As String
List1.Clear
Text1.Text = vbNullString
Open "MyDataFile" For Input As #1
MyData = Input(LOF(1), #1)
ArrItem = Split(MyData, vbCrLf)
For I = 0 To UBound(ArrItem) - 1
List1.AddItem ArrItem(I)
Next
Close
MsgBox "List Box has " & List1.ListCount & " items."
End Sub
Private Sub Form_Load()
' Build List Box
For I = 1 To ListSize
List1.AddItem I
Next
Text1.Text = vbNullString
End Sub
-
May 28th, 2009, 04:18 PM
#10
Thread Starter
Junior Member
Re: Print data from a ListBox (?)
Thanks everybody for their codes. I'm sure i will get it to work now.
Keep up the good work.
Tags for this Thread
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
|