krolm
04-11-2003, 04:18 PM
Hello all, first of all I'd like to say that I'm very new to visual basic, we just started working on it at school, and we have to make a project but I can't seem to get it to work. I tried searching the forum for answer to my question but without success.
Here it is:
I'm trying to make a simple kind of phonebook, using 2 forms: one for reading from a text based datafile, and one for writing to it.
The forms look like this, 4 textboxes, (first name, last name, phone number, adress), and a commandbutton to set it in motion.
The datafile is quite simple. A text file made with notepad, looking kind of like this..
2
John, Johnson, 555-4444, Johnstreet 6
Jack, Jackson, 666-5555, Jackstreet 9
the 2 would be the number of records, and the comma's seperate the different data. Now, for Reading the data from the file and displaying it in the proper textboxes, I have this code:
Private Sub Command1_Click()
Dim number As Integer
Dim n As Integer
Dim name(1000000#) As String
Dim phonenr(1000000#) As String
Dim lastname(1000000#) As String
Dim bdate(1000000#) As String
'1000000# is the maximum number of records that can be in the file
Open "C:\file.aaa" For Input As #1
'file.aaa would be the textfile
Input #1, number
For n = 1 To number
Input #1, name(n), lastname(n), bdate(n), phonenr(n)
Next n
Close #1
'now display in proper textboxes
For n = 1 To number
If name(n) = Text1 Then
Text2 = lastname(n)
Text3 = bdate(n)
Text4 = phonenr(n)
End If
If lastname(n) = Text2 Then
Text1 = name(n)
Text3 = bdate(n)
Text4 = phonenr(n)
End If
If bdate(n) = Text3 Then
Text1 = name(n)
Text2 = lastname(n)
Text4 = phonenr(n)
End If
If phonenr(n) = Text4 Then
Text1 = name(n)
Text2 = lastname(n)
Text3 = bdate(n)
End If
Next n
End Sub
-----------
(end of code)
This works fine, now the problem is, how can I make it write the strings the user types in the 4 textboxes to the bottom of the file and change the number of records that it holds? I tried to change the code using Output and Write instead of input but I seem to be doing something wrong.. Thank you for any help you can give me.
Here it is:
I'm trying to make a simple kind of phonebook, using 2 forms: one for reading from a text based datafile, and one for writing to it.
The forms look like this, 4 textboxes, (first name, last name, phone number, adress), and a commandbutton to set it in motion.
The datafile is quite simple. A text file made with notepad, looking kind of like this..
2
John, Johnson, 555-4444, Johnstreet 6
Jack, Jackson, 666-5555, Jackstreet 9
the 2 would be the number of records, and the comma's seperate the different data. Now, for Reading the data from the file and displaying it in the proper textboxes, I have this code:
Private Sub Command1_Click()
Dim number As Integer
Dim n As Integer
Dim name(1000000#) As String
Dim phonenr(1000000#) As String
Dim lastname(1000000#) As String
Dim bdate(1000000#) As String
'1000000# is the maximum number of records that can be in the file
Open "C:\file.aaa" For Input As #1
'file.aaa would be the textfile
Input #1, number
For n = 1 To number
Input #1, name(n), lastname(n), bdate(n), phonenr(n)
Next n
Close #1
'now display in proper textboxes
For n = 1 To number
If name(n) = Text1 Then
Text2 = lastname(n)
Text3 = bdate(n)
Text4 = phonenr(n)
End If
If lastname(n) = Text2 Then
Text1 = name(n)
Text3 = bdate(n)
Text4 = phonenr(n)
End If
If bdate(n) = Text3 Then
Text1 = name(n)
Text2 = lastname(n)
Text4 = phonenr(n)
End If
If phonenr(n) = Text4 Then
Text1 = name(n)
Text2 = lastname(n)
Text3 = bdate(n)
End If
Next n
End Sub
-----------
(end of code)
This works fine, now the problem is, how can I make it write the strings the user types in the 4 textboxes to the bottom of the file and change the number of records that it holds? I tried to change the code using Output and Write instead of input but I seem to be doing something wrong.. Thank you for any help you can give me.