Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Link a user from to a text file (Please HELP!!)

Status
Not open for further replies.

smartrider

Programmer
Apr 18, 2003
21
US
Hey I am new to VB therefore please help me out here.
I have created a user form which has the following fields :
Name (ListBox)
Phone Number :
Fax number .
the data is stored in a text file separated by "," . How can i link the Name Listbox with the text file and the other fields will automatically fill also.

I hope I am making sense.
Please help - This is my first job and I am really scared.

THanks
 

I am going to assume that you are using Visual Basic and not VBA (Visual Basic for Applications).

Here is an untested example you can try.

[tt]
Private Type MyType
Name As New Collection
Phone As New Collection
Fax As New Collection
End Type

Dim UserInfo As MyType

Private Sub Form_Load()

Dim FName As String, FNumb As Integer
Dim MySplit() As String, S As String

FName = App.Path & "\your_text_File_Name.txt"
FNumb = FreeFile

Open FName For Input As #FNumb
Do While Not EOF(FNumb)
Line Input #FNumb, S
MySplit = Split(S, ",")
List1.AddItem MySplit(0)
UserInfo.Name.Add MySplit(0)
UserInfo.Phone.Add MySplit(1)
UserInfo.Fax.Add MySplit(2)
Loop

Close #FNumb

End Sub

Private Sub List1_Click()

Dim I As Integer
For I = 0 To List1.ListCount - 1
If List1.Selected(I) = True Then
TextPhone.Text = UserInfo.Phone.Item(I)
TextFax.Text = UserInfo.Fax.Item(I)
Exit For
End If
Next I

End Sub
[tt]
The above example has no error checking nor has it been tested (I did this from memory so if something is wrong I or someone else should be able to help you).

Good Luck


 
You could also try to use the JET ISAM Text driver and create a connection on the text file and then bind the columns to the text boxes, if this is what you are looking for.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top