Private Sub btnSAVE_Click (sender As Object, As EventArgs e) Handles btnSAVE. Click
Dim Person As AdressList 'structure variables, used to save the file in a record
Dim RecCount As Integer 'total number of records in the file
Dim As Integer I
If the Trim (txtNUM. Text)="" Then 'number is zero, exit this process
MsgBox (" number can't be empty ")
TxtNUM. Focus ()
The Exit Sub
End the If
TxtNUM. Text=the Convert. ToString (Val (txtNUM. Text)) 'clear away the non-numeric characters in the Text box
TxtNUM. Text=Mid (txtNUM. Text + "", 1, 4) 'behind the Numbers up space
'return to the first record
If LOF (1) & gt; 0 Then
FileGet (1 Person, 1)
End the If
'to determine whether a new number in the record there
RecCount=1
The Do While EOF (1)=False
FileGet (1 Person, RecCount)
If the Person. The NUM=txtNUM. Text And State="new record" Then
MsgBox (" the same number already exists, please set a new serial number ")
TxtNUM. Text=""
TxtNUM. Focus ()
The Exit Sub
End the If
RecCount=RecCount + 1
Loop
TxtNAME. Text=Trim (txtNAME. Text)
If txtNAME. Text. Length=0 Then
MsgBox (" name cannot be empty, please note ")
TxtNAME. Focus ()
The Exit Sub
End the If
Person. The NUM=txtNUM. Text
Person. The NAME=txtNAME. Text
Person. SEX=rbdMAN. Checked
Person. The CITY=txtCITY. Text
Person. The ADRESS=txtADRESS. Text
Person. PHONE=txtPHONE. Text
Person. The CELL=txtCELL. Text
'ready to write to the file
If the State="record" Then
RecCount=LastRec () + 1 'run to an error here, in the current record content for {" error record length, "}
FilePut (1 Person, RecCount) 'the new code, name added to the list box, such as
IstNAME. Items. The Add (txtNUM. Text + "" + txtNAME. Text)
End the If
If the State="edit" Then
FilePut (1, a Person, a BookMark)
The State="new record"
'rewrite the content of the list box
IstNAME. Items. The Clear ()
RecCount=LastRec ()
For I=1 To RecCount
FileGet (1 Person, I)
IstNAME. Items. The Add (Person. NUM + "" + Person. NAME)
Next
End the If
TxtNUM. Text=""
TxtNAME. Text=""
TxtCITY. Text=""
TxtADRESS. Text=""
TxtPHONE. Text=""
TxtCELL. Text=""
RbdMAN. Checked=True
TxtNUM. Focus ()
End Sub
The generic function process LastRec ()
as followsPrivate Function LastRec () As an Integer
Dim RecCount As Integer
'in file to the total number of records in the
Dim Person As AdressList
'structure variable is used to save the file in a record
If LOF (1)=0 Then
'if the file size of 0 record number of 0
LastRec=0
The Exit Function
End the If
RecCount=1
FileGet (1 Person, RecCount)
The Do While EOF (1)=False
RecCount=RecCount + 1
FileGet (1 Person, RecCount)
Loop
MsgBox (" current record number is: "& amp; IstNAME. Items. Count & amp; "" & amp; RecCount & amp; "Article")
LastRec=RecCount
End the Function
CodePudding user response:
Self-study or teacher teach? That you learn is to use the skin of the vb.net to written set of vb6, don't astray,