FoxPro2.5第2部分
合集下载
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
常用函数
Date() 返回当前日期 Time() 返回当前时间 其它函数参见书P48
变量
给变量赋值有两种格式:
变量名=<变量值> Store <变量值> to 变量 例:cc=‘我爱北京天安门’
• D3=.T. • Store {97/07/07} to c_no
变量名不超过10个字符,由字母、数字或下划线 组成,且只能以字母打头,变量名中的大小写视 为一样。
判断分支结构
If <条件表达式>
<语句行序列>
Endif 当条件表达式为真时,执行语句行序列。 If <条件表达式>
<语句行序列1>
Else
<语句行序列2>
Endif 当条件表达式为真时,则执行语句行序列1,否则
执行语句行序列2。
判断分支结构举例
set talk ON use score clear xm=space(6) @3,5 say "请输入姓名" get xm read locate for 姓名==xm if found() display else @6,5 say "未找到" endif return
clear
use dang
do while .t.
a=space(4)
b=space(10)
c=space(10)
@10,20 say"请输入档号:" get a
@12,20 say"请输入题名:" get b
@14,20 say"请输入责任者:" get c
read
if a=space(4) then
单项检索
findrec2.prg
use dang clear a=space(4) @3,5 say "请输入档号:" get a read locate for alltrim(dh)==alltrim(a) do while found() display continue enddo return
FoxPro2.5 第2部分
编写一个简单程序
输入命令:modify command text.prg 在编辑窗口中输入以下程序语句:
clear ?"我们开始学习编程" @3,5 say "编程非常有趣" @10,10 say “这是一个好的开端” font “黑体”,30
按Esc键关闭编辑窗口 输入命令:do text.prg 来执行该程序
打开数据库后,字段也可以看做变量,叫字段变 量。随着记录指针的移动,字段的值不断发c1.prg
clear
use dang
a=space(4)
b=space(10)
c=space(10)
@10,20 say"请输入档号:" get a
@12,20 say"请输入题名:" get b
enddo
use
return
固定组配检索 findrec3.prg
use dang
clear
a=space(4)
b=space(10)
@3,5 say "请输入档号:" get a
@5,5 say "请输入题名:" get b
read
locate for alltrim(dh)==alltrim(a) .and. alltrim(tm)==alltrim(b)
exit
endif
添加记录的程序(2)
a=alltrim(a)
if len(a)<>4 then
@16,20 say"刚才所输入的档号位数不对,请重新输入该记录! "
wait
clear
loop
endif
append blank
go bottom
replace dh with a,tm with b,zrz with c
if len(a)<>0 .and. len(b)==0 then
locate for dh=a
endif
if len(a)<>0 .and. len(b)<>0 then
locate for dh=a .and. tm=b
endif
do while found()
display
continue
read
a=alltrim(a)
b=alltrim(b)
if len(a)==0 .and. len(b)==0 then
locate for len(dh)<>0
endif
if len(a)==0 .and. len(b)<>0 then
locate for tm=b
endif
组合检索(续)
do while found()
display
continue
enddo
return
组合检索
findrec4.prg
use dang
clear
a=space(4)
b=space(10)
@3,5 say "请输入档号: " get a
@5,5 say "请输入题名: " get b
上例中用到的函数
@行,列 say <提示信息> get <变量>
该命令在屏幕上指定的行和列位置显示提示信息,在 紧接提示信息之后等待用户输入变量值。变量应在此 之前赋一个初值,体现出该变量类型。另外该命令之 后配套使用read命令,方能激活输入。
Found()函数
在用locate命令查找记录时,如果找到,则found() 函数值为真(.T.),否则为假(.F.)。
Return
程序结束语句
循环结构
Do while <条件表达式>
<循环体>
Enddo 其中,do while <条件表达式>语句是循
环起始语句,enddo语句是循环结束语句。 当条件表达式为真时则执行循环,为假时 退出循环。
循环结构举例
set talk off clear use score do while .not. eof() display wait "按任意键显示下一条记录" skip enddo return
@14,20 say"请输入责任者:" get c
read
if a=space(4) then
return
endif
append blank
go bottom
replace dh with a,tm with b,zrz with c
use
return
添加记录的程序(2) addrec2.prg
enddo
use
return
单项检索
findrec1.prg
use dang clear a=space(4) @3,5 say "请输入档号:" get a read locate for alltrim(dh)==alltrim(a) if found() display else @6,5 say "未找到" endif return