看实例学VFP:对时间段进行查询的例子2009-02-10 本站 老马这个例子应用到了select语句中的between...and子句的知识,关于select语句请参考: 或。本例运行时如下图:

本例用到了“数据1”数据库中的“人员信息表”,关于该数据库的情况已经在一文中给出,这里不再详述。
制作步骤如下:一、新建表单,将其caption属性值设为“对时间段进行查询的例子”,width属性值设为290,height属性值设为195,AutoCenter属性值设为.t.,并将其保存为“对时间段进行查询的例子.scx”。二、向表单上添加两个Label控件,将它们的caption属性值分别设置为“出生日期在”和“与”,ForeColor属性值都设置为“0,0,255”,并将这两个Label控件排成一行。三、向表单上添加两个文本框控件,调整它们的位置,把两个Label控件间隔开,并把它们的Value属性值都设为“{}”(关于文本框控件的属性请参考:)。四、在文本框和Label控件的下方添加一个grid控件,并将其width属性值设为290,height属性值设为110。五、在grid控件下方再添加两个命令按钮command1和command2,并将它们的caption属性值分别设置为“查询”和“退出”。六、对表单上各控件的位置进行适当调整,调整后的表单设计器如下图:

七、添加事件代码:(一)表单的unload事件:close data(二)表单的init事件:
use 人员信息表with thisform.grid1.recordsource="人员信息表".deletemark=.f..visible=.t..readonly=.t..ColumnCount=8.Column1.Header1.Caption="编号".Column1.Header1.BackColor=RGB(255,255,190).Column2.Header1.BackColor=RGB(255,255,190).Column2.Header1.Caption="姓名".Column3.Header1.BackColor=RGB(255,255,190).Column3.Header1.Caption="部门".Column4.Header1.Caption="性别".Column4.Header1.BackColor=RGB(255,255,190).Column5.Header1.Caption="学历".Column5.Header1.BackColor=RGB(255,255,190).Column6.Header1.Caption="基本工资".Column6.Header1.BackColor=RGB(255,255,190).Column7.Header1.Caption="家庭住址".Column7.Header1.BackColor=RGB(255,255,190).Column8.Header1.Caption="出生日期".Column8.Header1.BackColor=RGB(255,255,190).Column1.width=40.Column2.width=50.Column3.width=50.Column4.width=30.Column5.width=60.Column6.width=60.Column7.width=60.Column8.width=60endwiththisform.grid1.Setall("DynamicBackColor","RGB(224,225,255)","Column")
(三)“查询”按钮(command1)的click事件:
if thisform.text1.value={}messagebox("请填入起始的出生日期",16,"系统提示")thisform.text1.setfocuselseif thisform.text2.value={}messagebox("请填入终止的出生日期",16,"系统提示")thisform.text2.setfocuselseSelect * from 人员信息表 where 出生日期;between thisform.text1.value and thisform.text2.value;into cursor 临时人员信息表with thisform.grid1.width=450.height=130.recordsource="临时人员信息表".deletemark=.f..visible=.t..ColumnCount=8.Column1.Header1.Caption="编号".Column1.Header1.BackColor=RGB(255,255,190).Column2.Header1.BackColor=RGB(255,255,190).Column2.Header1.Caption="姓名".Column3.Header1.BackColor=RGB(255,255,190).Column3.Header1.Caption="部门".Column4.Header1.Caption="性别".Column4.Header1.BackColor=RGB(255,255,190).Column5.Header1.Caption="学历".Column5.Header1.BackColor=RGB(255,255,190).Column6.Header1.Caption="基本工资".Column6.Header1.BackColor=RGB(255,255,190).Column7.Header1.Caption="家庭住址".Column7.Header1.BackColor=RGB(255,255,190).Column8.Header1.Caption="出生日期".Column8.Header1.BackColor=RGB(255,255,190).Column1.width=40.Column2.width=50.Column3.width=50.Column4.width=30.Column5.width=60.Column6.width=60.Column7.width=60.Column8.width=60endwiththisform.grid1.Setall("DynamicBackColor","RGB(224,225,255)","Column") endifendif
(四)“退出”按钮(command2)的click事件:thisform.release八、运行“对时间段进行查询的例子.scx”。参考资料:本例代码在Win2003+VFP6.0环境下调试通过。