|
-
Sep 22nd, 2007, 01:18 AM
#1
Thread Starter
PowerPoster
[RESOLVED] Load text to a list box?
Hi guys I was wondering I use the following code to load to a texbox from a textfile
VB Code:
Open App.Path & "\status.txt" For Append As #1
Write #1, "Manual"
Close #1
but how do I load to a listbox?
Thanks!!
-
Sep 22nd, 2007, 01:34 AM
#2
Re: Load text to a list box?
Code:
Private Sub Command1_Click()
dim line as string
fno = FreeFile()
Open App.Path & "\yourfile.txt" For Input As #fno
Do While Not EOF(fno)
Line Input #fno, Line
ListBox.AddItem Line
Loop
End Sub
Last edited by Fazi; Sep 22nd, 2007 at 01:38 AM.
-
Sep 22nd, 2007, 01:38 AM
#3
Re: Load text to a list box?
sorry, 2 lines have been altred in my code.
1. declaration of line variable
2. an unwanted endif
-
Sep 22nd, 2007, 09:00 AM
#4
Thread Starter
PowerPoster
Re: Load text to a list box?
Thank you
Can list boxes on QueryUnload Events write to a textfile as well?
-
Sep 22nd, 2007, 10:05 AM
#5
Re: Load text to a list box?
Listbox doesn't write anything to anywhere - you do that.
Code:
Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
Dim i As Integer
Open App.Path & "\status.txt" For Append As #1
For i = 0 To List1.ListCount - 1
Print #1, List1(i)
Next i
Close #1
End Sub
-
Dec 10th, 2007, 02:23 AM
#6
Thread Starter
PowerPoster
Re: Load text to a list box?
Sorry to bump this, but instead of making a new thread about a followup question I had about this I was just wondering..
I have a form called ignore and the query unload is part of the main form, form2. the list1 is on the ignore form. So my question is how do I get whatever is written to the list1 on the ignore form to be wirtten to the text file when the program is closed?
Thanks1!!
-
Dec 10th, 2007, 02:32 AM
#7
Re: Load text to a list box?
When dealing with controls from another form in the same application just simply call the forms name first
Code:
For i = 0 To Form1.List1.ListCount - 1
Print #1, Form1.List1(i)
Next i
Casey.
-
Dec 10th, 2007, 02:35 AM
#8
Lively Member
Re: Load text to a list box?
I'm guessing that the ignore form is still running while the main form is. If so, you can simply use the above code, and modify it to print the ignore forms list.
Example:
Code:
Open App.Path & "\status.txt" For Append As #1
For i = 0 To IgnoreForm.List1.ListCount - 1
Print #1, IgnoreForm.List1(i)
Next i
Close #1
Or use the query unload on the ignore form, so that any time it's closed, it prints to the designated text file.
Please use the search function prior to posting a question and see if someone's already answered it.
-If I helped you, please rate me, as I'd do the same for you =)
-Remember to select the Resolved option for your post when you've gotten the answers you need.
-
Dec 10th, 2007, 02:50 AM
#9
Thread Starter
PowerPoster
Re: Load text to a list box?
 Originally Posted by Neato
I'm guessing that the ignore form is still running while the main form is. If so, you can simply use the above code, and modify it to print the ignore forms list.
Example:
Code:
Open App.Path & "\status.txt" For Append As #1
For i = 0 To IgnoreForm.List1.ListCount - 1
Print #1, IgnoreForm.List1(i)
Next i
Close #1
Or use the query unload on the ignore form, so that any time it's closed, it prints to the designated text file.
Thanks, I put in the code, but I get an error stating "Wrong number of arugments or invalid property assignment" and it highlights the ".List1" in the line Print #1, IgnoreForm.List1(i)
????
-
Dec 10th, 2007, 02:51 AM
#10
Lively Member
Re: Load text to a list box?
Did you change 'IgnoreForm' to the name of your actual form?
Please use the search function prior to posting a question and see if someone's already answered it.
-If I helped you, please rate me, as I'd do the same for you =)
-Remember to select the Resolved option for your post when you've gotten the answers you need.
-
Dec 10th, 2007, 03:00 AM
#11
Thread Starter
PowerPoster
Re: Load text to a list box?
yes, the actual name is just ignore
-
Dec 10th, 2007, 03:17 AM
#12
Lively Member
Re: Load text to a list box?
Sorry about the delay, phone call.. Anyways.. Replace that line with:
Print #1, Ignore.List1.List(i)
And that should take care of your problem.
Please use the search function prior to posting a question and see if someone's already answered it.
-If I helped you, please rate me, as I'd do the same for you =)
-Remember to select the Resolved option for your post when you've gotten the answers you need.
-
Dec 10th, 2007, 04:44 AM
#13
Thread Starter
PowerPoster
Re: Load text to a list box?
Thank you so much !!!!!
Edit: Sorry to both you again but I was having a small problem with loading text to the list1 listbox.
The following code was posted in this thread
VB Code:
dim line as string
fno = FreeFile()
Open App.Path & "\yourfile.txt" For Input As #fno
Do While Not EOF(fno)
Line Input #fno, Line
ListBox.AddItem Line
Loop
Now while I use this code I get the error file is already open. I think that is because the load the textfile to the listbox is used before the write to listbox later on.
Does the textfile in the textfile to listbox get closed when it opens? Would that explain why when I get the error file is already open when It comes to the listbox to textfile code?
Thansk1!1
Last edited by Justin M; Dec 10th, 2007 at 05:07 AM.
-
Dec 10th, 2007, 09:46 AM
#14
Re: [RESOLVED] Load text to a list box?
When you open a file you should close it after you have finished with it so you dont get the error every time you try to open it again.
Code:
fno = FreeFile()
Open App.Path & "\yourfile.txt" For Input As #fno
Do While Not EOF(fno)
Line Input #fno, Line
ListBox.AddItem Line
Loop
Close #fno
Casey.
-
Dec 10th, 2007, 01:18 PM
#15
Thread Starter
PowerPoster
Re: [RESOLVED] Load text to a list box?
Thank you Casey, I changed the code a bit so it looks like this
VB Code:
fno = FreeFile()
Open App.Path & "\ignorelist.txt" For Input As #fno
Do While Not EOF(fno)
Line Input #fno, line
Ignore.List1.AddItem line
Loop
Close #fno
When I press the command button, I get the error arugment not optional and it highlights the "line" in the "Ignore.List1.AddItem line" line.
Would that mean I can't load to a list1 on another form this way?
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
|