回 帖 发 新 帖 刷新版面

主题:关于"查询"和"删除"按钮代码问题。

大家好,以下是本人遇到的问题,期待各位指教,谢谢。

我建立一个名为“学生成绩管理系统”数据库,库中有一名为“学生基本情况”的表,此表结构如下:学号(字符型),姓名(字符型),性别(字符型),出生年份(数值型),出生月份(数值型),年龄(数值型),入学年份(数值型),入学月份(数值型),专业代码(数值型)籍贯(字符型)联系电话(数值型)。

建立了一张表单,用于对上述的数据表进行操作,此表单只有五个按钮:增加记录,查询记录,修改记录,删除记录,退出。
以下是"增加记录"按钮的代码:
local xh, xm, xb, nl, jg, nian,yue, dianhua, zhuanye, ruxuenian, ruxueyue
xh=alltrim(THISFORM.text1.Value)
xm=alltrim(THISFORM.text2.Value)
xb=alltrim(THISFORM.text3.Value)
nl=alltrim(THISFORM.text4.Value)
jg=alltrim(THISFORM.text5.Value)
nian=alltrim(THISFORM.text6.Value)
yue=alltrim(THISFORM.text15.Value)
dianhua=alltrim(THISFORM.text7.Value)
zhuanye=alltrim(THISFORM.text8.Value)
ruxuenian=alltrim(THISFORM.text9.Value)
ruxueyue=alltrim(THISFORM.text16.Value)
go top
if len(xh)=0 .or. len(xh)!=10
  messagebox("请输入10位数学号!")
else
  LOCATE FOR  alltrim(学生基本情况.学号)==xh
  if found()
    messagebox("学号已存在,请重新输入学号!")
  else
     if len(xm)=0
        messagebox("请输入学生姓名!")
     else
        if len(xb)=0
           messagebox("请输入学生性别!")
        else
          if len(nl)=0
             messagebox("请输入学生年龄!")
          else
             if len(jg)=0
                messagebox("请输入学生籍贯!")
             else
               if len(nian)=0 .or. len(yue)=0
                  messagebox("请输入学生出生年月!")
               else
                  if len(dianhua)=0
                     messagebox("请输入联系电话!")
                  else
                     if len(zhuanye)=0 .or. len(zhuanye)!=5 
                        messagebox("请输入5位数专业代码!")
                     else
                        if len(ruxuenian)=0 .or. len(ruxueyue)=0
                           messagebox("请输入入学时间!")
                        else
                           if val(nl)>90
                              messagebox("年龄不能大于90岁!")
                           else
                              if xb!="男" .and. xb!="女"
                                 messagebox("性别只能输入“男”或“女”!")
                              else
                                 if val(nian)<1930 .or. val(nian)>2100
                                    messagebox("出生年份输入错误!")
                                 else
                                    if val(yue)<1 .or. val(yue)>12 
                                       messagebox("出生月份输入错误!")
                                    else
                                       if val(ruxuenian)<1930 .or. val(ruxuenian)>2100
                                          messagebox("入学年份输入错误!")
                                       else
                                          if val(ruxueyue)<1 .or. val(ruxueyue)>12
                                             messagebox("入学月份输入错误!")
                                          else
                                             append blank
                                             replace 学号 with alltrim(THISFORM.text1.Value)
                                             replace 姓名 with alltrim(THISFORM.text2.Value)
                                             replace 性别 with alltrim(THISFORM.text3.Value)
                                             replace 年龄 with val(alltrim(THISFORM.text4.Value))
                                             replace 籍贯 with alltrim(THISFORM.text5.Value)
                                             replace 出生年份 with val(alltrim(THISFORM.text6.Value))
                                             replace 出生月份 with val(alltrim(THISFORM.text15.Value))
                                             replace 联系电话 with val(alltrim(THISFORM.text7.Value))
                                             replace 专业代码 with val(alltrim(THISFORM.text8.Value))
                                             replace 入学年份 with val(alltrim(THISFORM.text9.Value))
                                             replace 入学月份 with val(alltrim(THISFORM.text16.Value))
                                             messagebox("学生信息添加成功!")
                                             THISFORM.text1.Value=""
                                             THISFORM.text2.Value=""
                                             THISFORM.text3.Value=""
                                             THISFORM.text4.Value=""
                                             THISFORM.text5.Value=""
                                             THISFORM.text6.Value=""
                                             THISFORM.text7.Value=""
                                             THISFORM.text8.Value=""
                                             THISFORM.text9.Value=""
                                             THISFORM.text15.Value=""
                                             THISFORM.text16.Value=""     
                                          endif
                                       endif
                                    endif                                 
                                 endif
                              endif
                           endif
                        endif
                     endif
                  endif               
               endif
             endif  
          endif
        endif
     endif
  endif
endif
thisform.refresh


以下是"查询记录"按钮的代码:
private xh
xh=alltrim(THISFORM.text1.Value)

go top
if len(xh)=0 .or. len(xh)!=10
  messagebox("请输入10位数学号!")
else
  locate for 学号==xh
    if .not. found()
       messagebox("找不到相关记录!") 
       THISFORM.text2.Value=""
       THISFORM.text3.Value=""
       THISFORM.text4.Value=""
       THISFORM.text5.Value=""
       THISFORM.text6.Value=""
       THISFORM.text15.Value=""
       THISFORM.text7.Value=""
       THISFORM.text8.Value=""
       THISFORM.text9.Value=""
       THISFORM.text16.Value=""
       thisform.refresh   
    else
       THISFORM.text2.Value=学生基本情况.姓名
       THISFORM.text3.Value=学生基本情况.性别
       THISFORM.text4.Value=学生基本情况.年龄
       THISFORM.text5.Value=学生基本情况.籍贯
       THISFORM.text6.Value=学生基本情况.出生年份
       THISFORM.text15.Value=学生基本情况.出生月份
       THISFORM.text7.Value=学生基本情况.联系电话
       THISFORM.text8.Value=学生基本情况.专业代码
       THISFORM.text9.Value=学生基本情况.入学年份
       THISFORM.text16.Value=学生基本情况.入学月份       
       endif 
endif
程序运行后,先用“增加记录”按钮是没有问题的,但按了“查询按钮”后,再按
“增加记录”按钮,就会出现以下提示:函数参数的值、类型或数目无效。请问是哪里出错?
另外,“删除记录”按钮的代码应怎样编写?

请高手尽快回复,急用,谢谢。

回复列表 (共2个回复)

沙发

将你if else endif 改为do case endcase会好看些。

板凳


请问是将哪里的if else endif 改为do case endcase?

我来回复

您尚未登录,请登录后再回复。点此登录或注册