下面这个程序是一个用户登陆的判断。有2个文本框和一个cmd控件,其中userindb是一个执行SQL语言的函数,参数1是SQL语句,参数2是指定列参数,比如:sqlstr = "select * from minisysmanage_inf  where 管理员ID='" + IDText.Text + "'"
userindb(sqlstr, 2) 
是读取sqlstr返回记录中第2列的数据
sysID,syspas,trytime是全局变量
如果正常登陆没有问题,但是我如果连续错误登陆好几次就会出现0x7788157f指令引用的0x03ddfffc内存。该内存不能为read这样的错误。这个问题很棘手,但是如果放着可能会导致后面的程序出现莫名的错误。
Private Sub cmdok_Click()
Dim sqlstr As String
If IDText.Text = "" Then
MsgBox "请输入次级服务器管理员ID", , "登陆错误"
Exit Sub
End IfIf Pastext.Text = "" Then
MsgBox "请输入次级服务器管理员密码", , "登陆错误"
Exit Sub
End If
If trytime > 3 Then
MsgBox "错误输入三次,系统将强行退出!", , "警告!"
Unload Me
userloading.Show
Exit Sub
End If
sqlstr = "select * from minisysmanage_inf  where 管理员ID='" + IDText.Text + "'"
If userindb(sqlstr, 2) = False Then
MsgBox "此用户不存在,请重新输入", , "警告"
trytime = trytime + 1
Else
If Pastext.Text <> trimstr(colvol) Then
MsgBox "密码错误,请重新输入", , "警告!"
trytime = trytime + 1
Exit Sub
Else
sysID = IDText.Text
syspas = Pastext.Text
minimanager_manage.Show
Unload Me
End If
End If
End SubPrivate Sub Form_Load()
trytime = 1
End SubPrivate Sub IDText_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then
Pastext.SetFocus
Exit Sub
End If
If check_ID_pas(KeyAscii) = False Then
MsgBox "合法的ID是大、小写字母和下划线", , "警告"
KeyAscii = 0
End If
End Sub
Private Sub Pastext_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then
cmdok.SetFocus
Exit Sub
End If
If check_ID_pas(KeyAscii) = False Then
MsgBox "合法的pas是大、小写字母和下划线", , "警告"
KeyAscii = 0
End If
End Sub

解决方案 »

  1.   

    不太清除,我估计和你的unload me 写法错误有关。unload me 后面是不允许有其他可执行的代码的,如果是这样的话,你可以跟踪一些你的代码,你会发现,unload me 之后程序还会执行下面的代码。这样窗体就实际上没有被卸载!!!If trytime > 3 Then
    MsgBox "错误输入三次,系统将强行退出!", , "警告!"
    Unload Me
    userloading.Show
    Exit Sub
    End If该写成:
    If trytime > 3 Then
        MsgBox "错误输入三次,系统将强行退出!", , "警告!"
        userloading.Show
        Unload Me
        Exit Sub
    End If同理,你要在所有的unload me 右面都加上一句 exit sub
    即:
    Unload Me
    Exit Sub你试试看好了。
      

  2.   

    MSDN上说:在卸载窗体时,只有显示的部件被卸载。和该窗体模块相关联的代码还保持在内存中。只有在运行时添加到窗体上的控件数组元素才能用 Unload 语句卸载。重新加载被卸载的控件时,其属性会被重新初始化。
      

  3.   

    trytime全局变量在哪里定义的?userloading使用了这个变量吗?
      

  4.   

    各为大虾,感谢你们的关心!
    我trytime是在模块里定义的,至于东西没卸载干净,我想在刚开始的时候装载的东西不多,应该都卸干净拉,不过我还是在看看。
    向你们敬礼!!!
      

  5.   

    userloading是个什么?使用了trytime变量吗?可否把trytime变量设置为过程内的static trytime as integer试试
      

  6.   

    userloading 是个窗体,有使用trytime变量,我试过用静态的,一样结果
      

  7.   

    各位大虾,经过3天的努力,我终于把它搞定了,感谢所有关注此话题的大虾,小虾,现在我无论怎么折磨它都不会出现错误。我现在把代码写下,希望大家能在以后的日子里避免犯同样的错误(其实到底是什么错误我还没弄清楚,但是我知道错误是有变量或者对象卸载不干净引起的,我就干脆全都卸载)
    Dim trytime As IntegerPrivate Sub cmdcancel_Click()userloading.Show
    Unload Me
    End SubPrivate Sub cmdok_Click()
    Dim sqlstr As String
    If IDText.Text = "" Then
    MsgBox "请输入主服务器管理员ID", , "登陆错误"
    Exit Sub
    End IfIf Pastext.Text = "" Then
    MsgBox "请输入主服务器管理员密码", , "登陆错误"
    Exit Sub
    End If
    If trytime > 3 Then
    MsgBox "错误输入三次,系统将强行退出!", , "警告!"
    End
    End If
    sqlstr = "select * from sysmanage_inf  where sysmanager_ID='" & IDText.Text & "'"
    If userindb(sqlstr, 2) = False Then
    MsgBox "此用户不存在,请重新输入", , "警告"
    trytime = trytime + 1
    If trytime > 3 Then
    MsgBox "您已经三次尝试进入本系统,均不成功,系统将关闭"
    End    Else
          Exit Sub
        End If
      End If
      '判断密码是否正确
    If trimstr(colvol) <> Pastext.Text Then
    MsgBox "密码错误"
    trytime = trytime + 1
    If trytime >= 3 Then
          MsgBox "您已经三次尝试进入本系统,均不成功,系统将关闭"
          End
        Else
          Exit Sub
        End If
        End If
    '登录成功,将当前用户的信息保存在sysID,syspas中
    sysID = IDText.Text
    syspas = Pastext.Text
    sysmanager_manage.Show
    Unload Me
    End SubPrivate Sub Form_Load()
    trytime = 1
    End SubPrivate Sub IDText_KeyPress(KeyAscii As Integer)
    If KeyAscii = 13 Then
    Pastext.SetFocus
    Exit Sub
    End If
    If check_ID_pas(KeyAscii) = False Then
    MsgBox "合法的ID是大、小写字母和下划线", , "警告"
    KeyAscii = 0
    End If
    End SubPrivate Sub Pastext_KeyPress(KeyAscii As Integer)
    If KeyAscii = 13 Then
    cmdok.SetFocus
    Exit Sub
    End If
    If check_ID_pas(KeyAscii) = False Then
    MsgBox "合法的pas是大、小写字母和下划线", , "警告"
    KeyAscii = 0
    End If
    End Sub
      

  8.   

    呵呵,最好是不要用END,不太规范,你该看看什么地方没有卸掉。这样做不规范的,只能是在万不得已的时候用用,嘿嘿。