Hi
Can you all help me fix it?
It done not print to the Listbox
Dim A As String
Private Sub Command1_Click()
End
End Sub
Private Sub List1_Click()
Open "C:\pos\bob\bob.txt" For Input As #1
Input #1, A
Close #1
List1.AddItem A
End Sub
Printable View
Hi
Can you all help me fix it?
It done not print to the Listbox
Dim A As String
Private Sub Command1_Click()
End
End Sub
Private Sub List1_Click()
Open "C:\pos\bob\bob.txt" For Input As #1
Input #1, A
Close #1
List1.AddItem A
End Sub
Ummm... did u define a? like
a = blah blah?
No!!!
Then why don't you? lol
I did it and it dose not work.
How does bob.txt look like? If you're reading a string, you need to have it between quotes. Otherwise use "Line Input", binary, or the FileSystem object.
bob.txt
bob
bob
For what you're doing, you'd need:
__________________
"bob"
"jack"
"some other guy"
__________________
Or use "Line Input" instead of "Input"
You could use this code as well. Put this in a module:
Then on your forum have 2 command buttons and 1 listbox. All default names.Code:Public Sub TextToList(WhatList As ListBox, TextFile$)
Rem Makes a .txt file from a listbox
On Error GoTo FartK
Dim X%
X% = FreeFile
Open TextFile$ For Input As #X
While Not EOF(X)
Input #X, sText$
DoEvents
WhatList.AddItem sText$
Wend
Close #X
Exit Sub
FartK:
Exit Sub
End Sub
In Command1 have:
And in Command2 since you wanted oen to end the program:Code:Private Sub Command1_Click()
TextToList List1, "C:\pos\bob\bob.txt"
End Sub
The above function will read a textfile on each line and put it into a Listbox of your choice. By pressing the Command1 button, you will open the textfile, and add all the lines in it into the Listbox on their own line, just as they were in the txt file.Code:Private Sub Command2_Click()
End
End Sub
new code
Option Explicit
Dim g
Dim h
Private Sub Command1_Click()
End
End Sub
Private Sub List1_Click(Index As Integer)
Open "C:\pos\bob.txt" For Input As #1
Line Input #1, g
Close #1
For X = 1 To 1
List1.AddItem g
Next X
End Sub
:confused:VB Code:
Dim A As String Private Sub Command1_Click() End End Sub Private Sub List1_Click() Open "C:\pos\bob\bob.txt" For Input As #1 Input #1, A Close #1 List1.AddItem A End Sub
You havn't assigned A a value. Therefore your file will be empty, plus the Command1_Click procedure has an error in it, it doesn't need to be there.
It is not working for me.
he got it work by ueing a Commandbtton.