CSDN首页 空间 新闻 论坛 Blog 下载 读书 网摘 搜索 .NET Java 视频 接项目 求职 在线学习 买书 程序员 通知
可用分押宝游戏火热进行中... 专题改版:Java Web 专题
CSDN社区
搜索 收藏 打印 关闭
CSDN社区 >  VB >  基础类

初学vb,请教

楼主xuanzi2002(小龙)2003-08-01 22:20:08 在 VB / 基础类 提问

我想做一个登陆的界面的有效性验证,我写了代码,但是运行有问题,请教  
  我代码贴出:  
  Dim   i   As   Integer  
  Private   Sub   Command1_Click()  
  If   Text1.Text   =   "admin"   And   Text2.Text   =   "master"   Then  
        Form2.Show  
        Unload   Form1  
        End   If  
         
   
        If   Text1.Text   =   "user"   And   Text2.Text   =   "work"   Then  
            Form2.Show  
            Unload   Form1  
            Form2.Cmd5.Enabled   =   False  
            Form2.Cmd6.Enabled   =   False  
            Form2.Cmd7.Enabled   =   False  
            End   If  
    If   (Text1.Text   <>   ""   And   Text2.Text   =   "")   Then  
              MsgBox   "口令不能为空,请输入正确的口令!"  
              Text2.SetFocus  
              End   If  
      If   (Text1.Text   =   ""   And   Text2.Text   <>   "")   Then  
              MsgBox   "用户名不能为空,请正确输入用户名!"  
              Text1.SetFocus  
              End   If  
   
        i   =   i   +   1  
      If   i   =   1   And   ((Text1.Text   <>   "admin"   And   Text2.Text   <>   "master")   Or   (Text1.Text   <>   "user"   And   Text2.Text   <>   "work"))   Then  
            MsgBox   "输入错误"  
            Text1.Text   =   ""  
            Text2.Text   =   ""  
            Text1.SetFocus  
            End   If  
      If   i   =   2   And   ((Text1.Text   <>   "admin"   And   Text2.Text   <>   "master")   Or   (Text1.Text   <>   "user"   And   Text2.Text   <>   "work"))   Then  
              MsgBox   "输入错误"  
            Text1.Text   =   ""  
            Text2.Text   =   ""  
            Text1.SetFocus  
            End   If  
      If   i   =   3   And   ((Text1.Text   <>   "admin"   And   Text2.Text   <>   "master")   Or   (Text1.Text   <>   "user"   And   Text2.Text   <>   "work"))   Then  
              MsgBox   "非法用户"  
              Unload   Me  
              End   If  
   
    End   Sub 问题点数:0、回复次数:12Top

1 楼liangshan(三楼楼长)回复于 2003-08-01 22:25:58 得分 0

什么问题?Top

2 楼gpo2002(永吹不休)回复于 2003-08-01 22:35:43 得分 0

Shell   Function  
               
   
  Runs   an   executable   program   and   returns   a   Variant   (Double)   representing   the   program's   task   ID   if   successful,   otherwise   it   returns   zero.  
   
  Syntax  
   
  Shell(pathname[,windowstyle])  
   
  The   Shell   function   syntax   has   these   named   arguments:  
   
  Part   Description    
  pathname   Required;   Variant   (String).   Name   of   the   program   to   execute   and   any   required   arguments   or   command-line   switches;   may   include   directory   or   folder   and   drive.    
  windowstyle   Optional.   Variant   (Integer)   corresponding   to   the   style   of   the   window   in   which   the   program   is   to   be   run.   If   windowstyle   is   omitted,   the   program   is   started   minimized   with   focus.    
   
   
  The   windowstyle   named   argument   has   these   values:  
   
  Constant   Value   Description    
  vbHide   0   Window   is   hidden   and   focus   is   passed   to   the   hidden   window.      
  vbNormalFocus   1   Window   has   focus   and   is   restored   to   its   original   size   and   position.    
  vbMinimizedFocus   2   Window   is   displayed   as   an   icon   with   focus.    
  vbMaximizedFocus   3   Window   is   maximized   with   focus.    
  vbNormalNoFocus   4   Window   is   restored   to   its   most   recent   size   and   position.   The   currently   active   window   remains   active.    
  vbMinimizedNoFocus   6   Window   is   displayed   as   an   icon.   The   currently   active   window   remains   active.    
   
   
  Remarks  
   
  If   the   Shell   function   successfully   executes   the   named   file,   it   returns   the   task   ID   of   the   started   program.   The   task   ID   is   a   unique   number   that   identifies   the   running   program.   If   the   Shell   function   can't   start   the   named   program,   an   error   occurs.  
   
  Note       By   default,   the   Shell   function   runs   other   programs   asynchronously.   This   means   that   a   program   started   with   Shell   might   not   finish   executing   before   the   statements   following   the   Shell   function   are   executed.    
   
  Top

3 楼gpo2002(永吹不休)回复于 2003-08-01 22:37:20 得分 0

不好意思哈,贴错了Top

4 楼pigpag(Pigpag - A GRE Fighter)回复于 2003-08-01 22:58:38 得分 0

同志们,问问题的时候要把问题说清楚。  
   
  最好说明问题出在那里。  
   
  这样的程序结构非常不好:修改  
  Dim   i   As   Integer  
  Private   Sub   Command1_Click()  
      If   Text1.Text   =   "admin"   And   Text2.Text   =   "master"   Then  
          Form2.Show  
          Unload   Form1  
          Exit   Sub           '<-修改  
      ElseIf   Text1.Text   =   "user"   And   Text2.Text   =   "work"   Then  
          Form2.Cmd5.Enabled   =   False  
          Form2.Cmd6.Enabled   =   False  
          Form2.Cmd7.Enabled   =   False  
          Form2.Show  
          Unload   Form1  
          Exit   Sub           '<-修改  
      ElseIf   Text1.Text   =   ""   Then             '<-修改  
          MsgBox   "用户名不能为空,请正确输入用户名!"  
          Text1.SetFocus  
      ElseIf   Text2.Text   =   ""   Then  
          MsgBox   "口令不能为空,请输入正确的口令!"  
          Text2.SetFocus  
      Else  
          i   =   i   +   1  
          If   (Text1.Text   <>   "admin"   And   Text2.Text   <>   "master")   Or   (Text1.Text   <>   "user"   And   Text2.Text   <>   "work")   Then  
              Select   Case   i  
              Case   1,   2  
                  MsgBox   "输入错误"  
                  Text1.Text   =   ""  
                  Text2.Text   =   ""  
                  Text1.SetFocus  
              Case   3  
                  MsgBox   "非法用户"  
                  Unload   Me  
              End   Select  
          End   If  
      End   If  
  End   Sub  
   
  这段程序很混乱,特别是后面,总觉得怪怪的,太冗长。而且  
  If   (Text1.Text   <>   "admin"   And   Text2.Text   <>   "master")   Or   (Text1.Text   <>   "user"   And   Text2.Text   <>   "work")   Then  
  这句判断很奇怪。是什么目的呢?你再仔细看看。Top

5 楼shenen(阿华)回复于 2003-08-01 23:14:27 得分 0

Dim   i   As   Integer  
  Private   Sub   Command1_Click()  
  If   Text1.Text   =   "admin"   And   Text2.Text   =   "master"   Then  
        Form2.Show  
        Unload   Form1  
        Exit   Sub  
  End   If  
         
  If   Text1.Text   =   "user"   And   Text2.Text   =   "work"   Then  
            Form2.Show  
            Unload   Form1  
            Form2.cmd5.Enabled   =   False  
            Form2.cmd6.Enabled   =   False  
            Form2.cmd7.Enabled   =   False  
            Exit   Sub  
  End   If  
  If   (Text1.Text   <>   ""   And   Text2.Text   =   "")   Then  
              MsgBox   "¤f&yen;O¤&pound;&macr;à&not;°&ordf;&Aring;&iexcl;A&frac12;&ETH;&iquest;é¤J&yen;&iquest;&Uacute;&Igrave;&ordf;&ordm;¤f&yen;O&iexcl;I"  
              Text2.SetFocus  
  End   If  
  If   (Text1.Text   =   ""   And   Text2.Text   <>   "")   Then  
              MsgBox   "&yen;&Icirc;¤á&brvbar;W¤&pound;&macr;à&not;°&ordf;&Aring;&iexcl;A&frac12;&ETH;&yen;&iquest;&Uacute;&Igrave;&iquest;é¤J¤J&yen;&Icirc;¤á&brvbar;W&iexcl;I"  
              Text1.SetFocus  
  End   If  
   
        i   =   i   +   1  
  If   i   =   1   And   ((Text1.Text   <>   "admin"   And   Text2.Text   <>   "master")   Or   (Text1.Text   <>   "user"   And   Text2.Text   <>   "work"))   Then  
            MsgBox   "&iquest;é¤J&iquest;ù&raquo;~"  
            Text1.Text   =   ""  
            Text2.Text   =   ""  
            Text1.SetFocus  
            End   If  
  If   i   =   2   And   ((Text1.Text   <>   "admin"   And   Text2.Text   <>   "master")   Or   (Text1.Text   <>   "user"   And   Text2.Text   <>   "work"))   Then  
              MsgBox   "&iquest;é¤J&iquest;ù&raquo;~"  
            Text1.Text   =   ""  
            Text2.Text   =   ""  
            Text1.SetFocus  
            End   If  
  If   i   =   3   And   ((Text1.Text   <>   "admin"   And   Text2.Text   <>   "master")   Or   (Text1.Text   <>   "user"   And   Text2.Text   <>   "work"))   Then  
              MsgBox   "&laquo;D&ordf;k&yen;&Icirc;¤á"  
              Unload   Me  
              End   If  
  End   Sub  
   
  'Let's   study   VB   together.  
  'When   then   form   is   unload,You   can't   reference   it's   control.Top

6 楼shenen(阿华)回复于 2003-08-01 23:20:15 得分 0

Dim   i   As   Integer  
  Private   Sub   Command1_Click()  
  If   Text1.Text   =   "admin"   And   Text2.Text   =   "master"   Then  
        Form2.Show  
        Unload   Form1  
        Exit   Sub  
  End   If  
         
  If   Text1.Text   =   "user"   And   Text2.Text   =   "work"   Then  
            Form2.Show  
            Unload   Form1  
            Form2.cmd5.Enabled   =   False  
            Form2.cmd6.Enabled   =   False  
            Form2.cmd7.Enabled   =   False  
            Exit   Sub  
  End   If  
  If   (Text1.Text   <>   ""   And   Text2.Text   =   "")   Then  
              MsgBox   "口令不能为空,请输入正确的口令!""  
              Text2.SetFocus  
  End   If  
  If   (Text1.Text   =   ""   And   Text2.Text   <>   "")   Then  
              MsgBox   "用户名不能为空,请正确输入用户名!""  
              Text1.SetFocus  
  End   If  
   
  i   =   i   +   1  
  If   i   =   1   And   ((Text1.Text   <>   "admin"   And   Text2.Text   <>   "master")   Or   (Text1.Text   <>   "user"   And   Text2.Text   <>   "work"))   Then  
            MsgBox   "输入错误"  
            Text1.Text   =   ""  
            Text2.Text   =   ""  
            Text1.SetFocus  
            End   If  
  If   i   =   2   And   ((Text1.Text   <>   "admin"   And   Text2.Text   <>   "master")   Or   (Text1.Text   <>   "user"   And   Text2.Text   <>   "work"))   Then  
              MsgBox   "输入错误"  
            Text1.Text   =   ""  
            Text2.Text   =   ""  
            Text1.SetFocus  
            End   If  
  If   i   =   3   And   ((Text1.Text   <>   "admin"   And   Text2.Text   <>   "master")   Or   (Text1.Text   <>   "user"   And   Text2.Text   <>   "work"))   Then  
              MsgBox   "非法用户"  
              Unload   Me  
              End   If  
  End   Sub  
  '剛才貼成了亂碼,重貼!  
   
  Top

7 楼xuanzi2002(小龙)回复于 2003-08-01 23:52:43 得分 0

to   pigpag(噼里啪啦)    
      为什么要加上end   sub   这句啊  
  我才学的,都不知道问什么好了Top

8 楼xuanzi2002(小龙)回复于 2003-08-01 23:59:43 得分 0

to   pigpag(噼里啪啦)    
      你写的我不能运行,提示,ELSE   没有IFTop

9 楼huangy0153(遥遥)回复于 2003-08-02 00:45:44 得分 0

写密码程序干吗要这样写?你用combo控件吧,然后用case,不是挺方便的吗,不用老是IF了Top

10 楼csdngoodnight(居然比我还快,你真行!)回复于 2003-08-02 07:36:09 得分 0

Dim   i   As   Integer  
  Private   Sub   Command1_Click()  
          if   i   >   3     then    
                  msgbox"已经三次错误,退出"  
                  '这里填上退出程序的代码  
                  exit   sub  
          endif  
          If   Text1.Text   =   "admin"   And   Text2.Text   =   "master"   Then  
                  Form2.Show  
                  Unload   Form1  
          elseIf   Text1.Text   =   "user"   And   Text2.Text   =   "work"   Then  
                  Form2.Cmd5.Enabled   =   False  
                  Form2.Cmd6.Enabled   =   False  
                  Form2.Cmd7.Enabled   =   False  
                  Form2.Show         '这里注意窗口焦点  
                  Unload   Form1      
          elseif   (Text1.Text   <>   ""   And   Text2.Text   =   "")   Then  
                  MsgBox   "口令不能为空,请输入正确的口令!"  
                  Text2.SetFocus  
          ElseIf   (Text1.Text   =   ""   And   Text2.Text   <>   "")   Then  
                  MsgBox   "用户名不能为空,请正确输入用户名!"  
                  Text1.SetFocus  
          End   If  
   
          i   =   i   +   1  
  End   Sub  
  Top

11 楼zmrok(朱朱)回复于 2003-08-02 12:32:56 得分 0

if   trim(text1.text)=""   or   trim(text2.text)=""   then  
        msgbox"用户名和密码不为空"  
        exit   sub  
  end   if  
  select   case   text1.text  
      case   "admin"  
          if   text2.text="master"   then  
                Form2.Show  
                Unload   Form1  
                Form2.Cmd5.Enabled   =   False  
                Form2.Cmd6.Enabled   =   False  
                Form2.Cmd7.Enabled   =   False  
              else  
                  if   i   >   2   then  
                      i=i+1  
                      msgbox"密码错误"  
                      exit   sub  
                    else  
                      msgbox"非法用户"  
                      exit   sub  
                  end   if  
              end   if  
        case   "user"  
              if   text2.text="work"   then  
                 
                Form2.Show  
                Unload   Form1  
                Form2.Cmd5.Enabled   =   False  
                Form2.Cmd6.Enabled   =   False  
                Form2.Cmd7.Enabled   =   False  
              else  
                   
                  if   i   >   2   then  
                      i=i+1  
                      msgbox"密码错误"  
                      exit   sub  
                    else  
                      msgbox"非法用户"  
                      exit   sub  
                  end   if  
              end   if  
        end   select  
  Top

12 楼xuanzi2002(小龙)回复于 2003-08-03 15:04:05 得分 0

谢大家了Top

相关问题

  • vb初学者
  • 初学vb,help me!!
  • 初初学vb , 再问!!
  • 初学VB,菜鸟问题
  • vb初学,有小问题。
  • 溢出问题,初学VB.
  • 初学VB者的问题?
  • 初学VB,小问题
  • 帮帮我!VB初学者问
  • 初学VB,看什么书好?

关键词

  • 口令
  • 用户
  • 代码
  • 密码
  • program
  • msgbox
  • setfocus
  • windowstyle
  • 输入
  • cmd

得分解答快速导航

  • 帖主:xuanzi2002

相关链接

  • Visual Basic类图书
  • Visual Basic类源码下载

广告也精彩

反馈

请通过下述方式给我们反馈
反馈
提问
网站简介|广告服务|VIP资费标准|银行汇款帐号|网站地图|帮助|联系方式|诚聘英才|English|问题报告
世纪乐知(北京)网络技术有限公司 版权所有, 京 ICP 证 020026 号
北京创新乐知广告有限公司 提供技术支持
Copyright © 2000-2007, CSDN.NET, All Rights Reserved
GongshangLogo