Option Explicit
Private Declare Function GetUserName Lib "advapi32.dll" Alias "GetUserNameA" (ByVal lpbuffer As String, nSize As Long) As Long     
'上面这两行是什么意思啊,我不知道Public OK As Boolean
'记录确定次数
Dim miCount As Integer
Private Sub Form_Load()
    Dim sBuffer As String
    Dim lSize As Long
    sBuffer = Space$(255) '这干嘛的
    lSize = Len(sBuffer)  
    Call GetUserName(sBuffer, lSize) '这干嘛的
    If lSize > 0 Then
        txtUserName.Text = ""
   
    Else
        txtUserName.Text = vbNullString ' 这个是什么啊
    End If
        OK = False
    miCount = 0
End SubPrivate Sub cmdCancel_Click()
    OK = False
    Me.Hide
End Sub
Private Sub cmdOK_Click()
    Dim txtSQL As String
    Dim mrc As ADODB.Recordset '不用加NEW吗
    Dim MsgText As String
    'ToDo: create test for correct password
    'check for correct password   '这里代码怎么写啊
    
    
    UserName = ""
    If Trim(txtUserName.Text = "") Then
        MsgBox "没有这个用户,请重新输入用户名!", vbOKOnly + vbExclamation, "警告"
        txtUserName.SetFocus
    Else
        txtSQL = "select * from user_Info where user_ID = '" & txtUserName.Text & "'"
        Set mrc = ExecuteSQL(txtSQL, MsgText)                         
  '上面一行我不懂,呵呵
        If mrc.EOF = True Then
            MsgBox "没有这个用户,请重新输入用户名!", vbOKOnly + vbExclamation, "警告"
            txtUserName.SetFocus
        Else
            If Trim(mrc.Fields(1)) = Trim(txtPassword.Text) Then
                OK = True
                mrc.Close
                Me.Hide
                UserName = Trim(txtUserName.Text)
            Else
                MsgBox "输入密码不正确,请重新输入!", vbOKOnly + vbExclamation, "警告"
                txtPassword.SetFocus
                txtPassword.Text = ""
            End If
        End If
    End If
    
    miCount = miCount + 1
    If miCount = 3 Then
        Me.Hide
    End If
    Exit Sub
End Sub大家帮帮忙好吗,我是初学者,现在正急呢?谢谢!

解决方案 »

  1.   

    Private Declare Function GetUserName Lib "advapi32.dll" Alias "GetUserNameA" (ByVal lpbuffer As String, nSize As Long) As Long     '这是获得当前登录用户名的API函数.sBuffer = Space$(255)'将这个变量附值为255个空格.txtUserName.Text = vbNullString '设为空Dim mrc As ADODB.Recordset '不用加NEW吗(因为后面有代码附一个值给这个对象,所以不用)
      

  2.   

    因为用了Set mrc = ExecuteSQL(txtSQL, MsgText)来附值给mrc 了,所以mrs定义时不用NEW
      

  3.   

    ExecuteSQL应该是自己定义的函数
      

  4.   

    谢谢先,那ExeuteSQL好像那个页面没有,不知道怎么做,呵呵,能帮吗