具体程序如下:
Private Function checkblank() As Boolean '¼ì²é×¢²áÓû§ÐÅÏ¢ÊÇ·ñÈ«ÊäÈë
checkblank = False
Dim myStrMsg As String
myStrMsg = ""
   If TxtName.Text = "" Then
      myStrMsg = "请填写姓名"
      TxtName.SetFocus
   End If
   If myStrMsg = "" Then
      If TxtId.Text = "" Then
         myStrMsg = " 请填写有效证件号码¡"
         TxtId.SetFocus
         Exit Function
      End If
   End If
   If myStrMsg = "" Then
      If TxtPassword1.Text = "" Then
         myStrMsg = "请输入密码¡"
         TxtPassword1.SetFocus
      End If
   End If
   If myStrMsg = "" Then
      If TxtPassword2.Text = "" Then
         myStrMsg = "请确认密码¡"
         TxtPassword2.SetFocus
      End If
   End If
   If myStrMsg = "" Then
     If Trim(TxtPassword1.Text) = Trim(TxtPassword2.Text) Then
        TxtNote.SetFocus
     Else
        myStrMsg = "输入密码与之前不一致,请再次输入密码"
        TxtPassword1.SetFocus
     End If
   End If
checkblank = True
End Function
为什么TxtName为空还是能继续输入,不会出现“请填写姓名”的提示,而且密码前后不一致,也没反应,都能输入到数据库?

解决方案 »

  1.   

    最开始的private fuction checkbland()as boolean后面那些是中文,由VB上copy下来变成乱码了,原文是“判断注册用户输入信息是否为空”
      

  2.   

    Private Function checkblank() As Boolean '¼ì²é×¢²áÓû§ÐÅÏ¢ÊÇ·ñÈ«ÊäÈë
    checkblank = False
    Dim myStrMsg As String
    myStrMsg = ""
       If TxtName.Text = "" Then
          myStrMsg = "请填写姓名"
          TxtName.SetFocus
          exit function
       End If
       'If myStrMsg = "" Then
          If TxtId.Text = "" Then
             myStrMsg = " 请填写有效证件号码¡"
             TxtId.SetFocus
             Exit Function
          End If
       'End If
       'If myStrMsg = "" Then
          If TxtPassword1.Text = "" Then
             myStrMsg = "请输入密码¡"
             TxtPassword1.SetFocus
             Exit Function
          End If
       'End If
       'If myStrMsg = "" Then
          If TxtPassword2.Text = "" Then
             myStrMsg = "请确认密码¡"
             TxtPassword2.SetFocus
             Exit Function
          End If
       'End If
       'If myStrMsg = "" Then
         If Trim(TxtPassword1.Text) = Trim(TxtPassword2.Text) Then
            TxtNote.SetFocus
         Else
            myStrMsg = "输入密码与之前不一致,请再次输入密码"
            TxtPassword1.SetFocus
             Exit Function
         End If
       'End If
    checkblank = True
    End Function
      

  3.   

    Private Function checkblank() As Boolean '¼ì²é×¢²áÓû§ÐÅÏ¢ÊÇ·ñÈ«ÊäÈë
    checkblank = False
    Dim myStrMsg As String
    myStrMsg = ""
       If TxtName.Text = "" Then
          myStrMsg = "请填写姓名"
          TxtName.SetFocus
          exit function  '加上这个
       End If
       If myStrMsg = "" Then
          If TxtId.Text = "" Then
             myStrMsg = " 请填写有效证件号码¡"
             TxtId.SetFocus
             Exit Function
          End If
       End If
       If myStrMsg = "" Then
          If TxtPassword1.Text = "" Then
             myStrMsg = "请输入密码¡"
             TxtPassword1.SetFocus
             exit function  '加上这个
          End If
       End If
       If myStrMsg = "" Then
          If TxtPassword2.Text = "" Then
             myStrMsg = "请确认密码¡"
             TxtPassword2.SetFocus
              exit function  '加上这个
          End If
       End If
       If myStrMsg = "" Then
         If Trim(TxtPassword1.Text) = Trim(TxtPassword2.Text) Then
            TxtNote.SetFocus
            
         Else
            myStrMsg = "输入密码与之前不一致,请再次输入密码"
            TxtPassword1.SetFocus
            exit function  '加上这个
         End If
       End If
    checkblank = True
    End Function
      

  4.   

    提示一个问题,如果比较字符串.最好加上Trim(varryname)=""去除空格
      

  5.   

    If TxtName.Text = "" Then
          myStrMsg = "请填写姓名"
          TxtName.SetFocus
       End If
    上面的程序段中必须加上exit function