PDA

Click to See Complete Forum and Search --> : Totally confused This is not for School but for personal learning


Jessie
Nov 29th, 1999, 12:47 PM
I have a list of text files in a folder called MovieRentals. The File names are stored like Phone Numbers (555)-555-5555
when the program starts you are prompted to enter a phone number. i cannot figure out how to access the files and retrive the information in the files and put them into textBoxes this code is a test that i am running not the actual program can some one tell me what's wrong with it or show me a example that works I known parts of the code is wrong but not sure how to fix it
thxs in advance :)
Eg
(555)-555-5555
name
last name
address
phone number

Option Explicit
Dim strFileName As String
Dim strMember As String
Dim strNam As String
Dim intFreeFile As Integer


Private Sub Command1_Click()
txtMember = strFileName
strFileName = Dir("d:\MovieRental")
intFreeFile = FreeFile

Open strFileName For Append As intFreeFile
Do
Line Input #intFreeFile, strMember
Line Input #intFreeFile, strNam
Loop Until (EOF)
Close #intFreeFile
Pass_Values
End Sub
Private Sub Pass_Values()

txtText1 = strMember
txtText2 = strNam
End Sub


[This message has been edited by Jessie (edited 11-30-1999).]

SteveS
Nov 29th, 1999, 01:22 PM
You should open the file for "input" NOT "append".

Append sets you to the end of the file,input sets you to the begining of the file.

Also in the strFileName, include the extention of the file
ie: "D:\MovieRental.Txt"

Also everytime you loop thrugh the code reading in a line from the file, you are overwriting the previously read line without storing the information.

Try something like
Create an array of TextBoxes called
txtMyTextBox, then use the following code

Private strLineInfo() as String

intLC = 0
Open strFileName for Input as #1
Do While NOT EOF(1)
ReDim Preserve strLineInfo(intLC)
Input #1,strLineInfo(intLC)
intLC = intLC + 1
Loop
Close #1

For n = 0 to intLC
txtMyTextBox(n).Text = strLineInfo(n)
Next n

Jessie
Nov 29th, 1999, 01:54 PM
Thxs SteveS i am learning Vb at home sometimes it gets frustrating do nothing but reading to find the answers and when you think that you find them the code doesn't work the way you think it should
regards Jessie :)