Private Sub cmdOK_Click()
    '检查正确的密码
    If txtPassword.Text = "" Then
            MsgBox "Please input password!"
            Exit Sub
        End If
        '先检查是否填好用户名与密码
       If txtname.Text = "" Then
            MsgBox "Please input  username!"
            Exit Sub
       End If
      Dim temp2 As string, temp3 As string, temp4 As String, temp5 As String
      temp2 = Trim$((strpassword)
      temp3 = Trim$(txtPassword.Text)
      temp4 = strusername
      temp5 = txtname.Text
      'MsgBox strusername
      '****************************************
    If txtPassword = "1" Then
        LoginSucceeded = True
        Me.Hide
        frmmain.Show
        Exit Sub
        '超级用户登录
    End If
   
    If temp4 = temp5 Then  '用户名正确
        MsgBox " username=" & temp4
    Else
        MsgBox "用户名错误,请重试!"
        Exit Sub
    End If
    If temp2 = temp3 Then  '如果密码正确
            MsgBox txtPassword
            LoginSucceeded = True
            frmmain.Show
            Me.Hide
            Exit Sub
    Else
           
            MsgBox "密码错误,请重试!", , "登录"
           txtname.SetFocus
            SendKeys "{Home}+{End}"
    End If
   
       
       
    
End Sub
Private Sub Form_Load()
     If Right(App.Path, 1) = "\" Then
        temp1 = ReadIni(App.Path & "user.ini", "user", "name", strusername)
        temp2 = ReadIni(App.Path & "user.ini", "user", "password", strpassword)
       
    Else
        temp1 = ReadIni(App.Path & "\user.ini", "user", "name", strusername)
        temp2 = ReadIni(App.Path & "\user.ini", "user", "password", strpassword)
        
    End If
End Sub
注:ReadIni为在公用模块中的读ini文件的函数.
这一段程序除了可以用超级用户登录外,怎样都无法进入,请各位帮忙!

解决方案 »

  1.   

    temp1变量没有声明。看程序中应该就是temp4,用来存放用户名名的!!把Form_Load中的temp1换成temp4试试!
      

  2.   

    你调用Api读取INI文件中的值时,需要指定存储数据变量的长度,如果长度不足,则取出的值将会被截取满足长度的那一部分,如果变量长度大于取出值的长度,则剩余部分要有空格填补,你需要经多余的空白删除。
      

  3.   


    检测一下ReadIni函数获取的strusername及strpassword  的值
    是否同ini文件中设置的一致
      

  4.   

    你可以看看temp1和temp2取出来等于什么
      

  5.   

    temp4 = strusernametemp4 = "strusername"
      

  6.   

    我很粗心......,应该是
    Dim temp1 As Long, temp2 As Long '定义读取配置文件的结果
    Dim temp3 As String, temp4 As String, temp5 As String, temp6 As String
    '四个临时变量分别储存取出和输入的密码与用户名
    但是完全改了也不行啊......
    改正的代码如下:
    Dim temp1 As Long, temp2 As Long '定义读取配置文件的结果
    Dim temp3 As String, temp4 As String, temp5 As String, temp6 As String
    '四个临时变量分别储存取出和输入的密码与用户名
    Private Sub cmdOK_Click()
    '检查正确的密码
    If txtPassword.Text = "" Then
    MsgBox "Please input password!"
    Exit Sub
    End If
    '先检查是否填好用户名与密码
    If txtname.Text = "" Then
    MsgBox "Please input username!"
    Exit Sub
    End If
    temp3 = Trim$(strpassword)
    temp4 = Trim$(txtPassword.Text)
    temp5 = strusername
    temp6 = txtname.Text
    '****************************************
    If txtPassword = "1" Then
    LoginSucceeded = True
    Me.Hide
    frmmain.Show
    Exit Sub
    '超级用户登录
    End IfIf temp5 = temp6 Then '用户名正确
    MsgBox " username=" & temp4
    Else
    MsgBox "用户名错误,请重试!"
    Exit Sub
    End If
    If temp3 = temp4 Then '如果密码正确
    MsgBox txtPassword
    LoginSucceeded = True
    frmmain.Show
    Me.Hide
    Exit Sub
    ElseMsgBox "密码错误,请重试!", , "登录"
    txtname.SetFocus
    SendKeys "{Home}+{End}"
    End If
    End Sub
    Private Sub Form_Load()
    If Right(App.Path, 1) = "\" Then
    temp1 = ReadIni(App.Path & "user.ini", "user", "name", strusername)
    temp2 = ReadIni(App.Path & "user.ini", "user", "password", strpassword)Else
    temp1 = ReadIni(App.Path & "\user.ini", "user", "name", strusername)
    temp2 = ReadIni(App.Path & "\user.ini", "user", "password", strpassword)End If
    end sub
      

  7.   

    这一句好像有问题:
    Dim temp2 As string, temp3 As string, temp4 As String, temp5 As String应该是:
    Dim temp2, temp3, temp4, temp5 As String

    Dim temp2 As string
    Dim temp3 As string
    Dim temp4 As String
    Dim temp5 As String验证密码不需要 Trim()程序似乎写复杂了
      

  8.   

    取出值检查过了,
    Dim temp3 As string
    Dim temp4 As string
    Dim temp5 As String
    Dim temp6 As String
    也改过了,应该和这个无关的
      

  9.   

    谢谢兄弟们热情帮助!原因已经查明,只要把temp3,temp4,temp5,temp6四个变量的声明各自改为:dim temp3 as string *15,就可以啦!