小程序,<注册--登陆验证>问题,总是不成功,请教各位大侠
做了小程序,注册时用数据文件记录注册信息(2项,用户名跟密码),登陆时读文件取记录跟用户的输入做判断,结果每次都失败,原因在哪?
Module1:
Public Type UserInfo
Nam As String * 20
Pwd As String * 20
End Type
Public Function Login(ByVal strUserNam As String, ByVal strUserPwd As String) As Boolean
Dim intFnum, intLast, i As Integer
Dim User As UserInfo
intFnum = FreeFile
Open "apppath & xx.dat" For Random As intFnum Len = Len(User)
intLast = LOF(intFnum) / Len(User)
For i = 1 To intLast
Get #intFnum, i, User
If User.Nam = strUserNam And User.Pwd = strUserPwd Then
Login = True
Exit For '不考虑用户名重复
End If
Next i
Close #intFnum
End Function
frmLogin: '登陆窗口代码
Private Sub cmdRegist_Click()
Me.Hide
frmRegist.Show
End Sub
Private Sub cmdLogin_Click()
If Login(Trim(txtName.Text), Trim(txtPassword.Text)) = True Then
MsgBox "登陆成功!"
Else
MsgBox "登陆失败!"
End If
End Sub