呵呵写了个vb 验证代码
碰到错误时怎么让他不执行下一句比如:用户空时,就不要再往下验证密码Private Sub cmdOK_Click()
    
 
    '用户名是否为空
      If txtUserName = "" Then
      MsgBox "未输入用户名"
   
      End If
      
      If txtPassword = "" Then
      MsgBox "未输入密码!"
      
      End If
end sun

解决方案 »

  1.   

    Private Sub cmdOK_Click()
        
     
        '用户名是否为空
          If txtUserName = "" Then
          MsgBox "未输入用户名"
          Exit Sub
          End If
          
          If txtPassword = "" Then
          MsgBox "未输入密码!"
          
          End If
    end sub
      

  2.   

    Private Sub cmdOK_Click()
        
     
        '用户名是否为空
          If txtUserName = "" Then
          MsgBox "未输入用户名"      exit sub'退出过程
       
          End If
          
          If txtPassword = "" Then
          MsgBox "未输入密码!"
          
          End If
    end sun
      

  3.   

    Private Sub cmdOK_Click()
        
     
        
          If txtUserName = "" or txtPassword = "" 
     Then
          MsgBox "未输入用户名或未输入密码!"
    textusername.setfocus
          
          End If
          
          end sub