1 / 27

VF程序设计(3)

VF程序设计(3). 计算机教研室 蔡海洋. 模块化、面向对象、表单. 例3:输出如下图形. * ** *** **** ***** ****** ******* ******** *********. for i=1 to 9 step 1 ? for j=1 to i step 1 ?? "*" endfor endfor. 九九乘法表. for i=1 to 9 step 1 ? for j=1 to i step 1 h=j*i

ronny
Download Presentation

VF程序设计(3)

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. VF程序设计(3) 计算机教研室 蔡海洋 模块化、面向对象、表单

  2. 例3:输出如下图形 * ** *** **** ***** ****** ******* ******** ********* for i=1 to 9 step 1 ? for j=1 to i step 1 ??"*" endfor endfor

  3. 九九乘法表

  4. for i=1 to 9 step 1 ? for j=1 to i step 1 h=j*i ??STR(j,3)+"*"+STR(i,1)+"="+STR(h,2) endfor endfor

  5. input " C(m-n)的n=" to n input "C(m-n)的m=" to m tn=1 for i=1 to n tn= tn*i endfor tm=1 for i=1 to m tm= tm*i endfor tnm=1 for i=1 to n-m tnm= tnm*i endfor ?"C(m-n)=",tn/(tm*tnm)

  6. 自定义函数方法 input "C(m-n)的n=" to n input "C(m-n)的m=" to m w= jiecheng(n) / (jiecheng(m)*jiecheng(n-m)) ?"C(m-n)=",alltrim(str(w)) function jiecheng parameters x t=1 for i=1 to x t= t*i endfor return t jiecheng1.prg

  7. 过程方法 input "C(m-n)的n=" to n input "C(m-n)的m=" to m store 1 to tn, tm, tnm do jiecheng with n,tn do jiecheng with m,tm do jiecheng with n-m,tnm w=tn/(tm*tnm) ?"C(m-n)=",alltrim(str(w)) procedure jiecheng parameters x,t for i=1 to x t= t*i endfor return jiecheng2.prg

  8. 过程函数总结 主程序中用:do 过程名 with 参数表 主程序中用:像函数一样使用 过程调用 函数调用 过程:用procedure定义 第一句是:parameters 变量表 .... return 自定义函数:用 function 定义 第一句是: parameters变量表 .... return 返回值

  9. 实参是常量、表达式——按值传递 (1)一般 实参是变量——按址传递(形参和实参为同一地址) 参数传递总结 子程序(过程) 实参带括号——按值方式传递 自定义函数 (2) set udfparms to value默认:按值传递(形参不会影响实参) (3) set udfparms to reference:按引用传递(形参会影响实参)

  10. 例9.18 写出下列程序的输出 a x=1 y=3 do sub with x, (y), 5 ?x,y procedure sub parameter a, b, c a=a+b+c b=a+b-c return x 1 9 y 3 b 3 7 c 5

  11. 变量作用域 1. 一般变量:上级程序定义的变量在本程序及下级程序中起作用;下级程序所定义的变量当自身程序执行完毕便释放。2. public变量-全局变量,在所有程序中起作用;3. private变量-私有变量,在本级及下级程序中起作用,同时屏蔽上级同名变量;4. local变量-局部变量,在本级程序中起作用,在下级程序中不起作用,同时可以屏蔽上级同名变量。

  12. public变量 private private变量 local local

  13. 第10章 面向对象程序设计基础 1 对象(Object) 客观世界里的任何实体都可以被看作是对象。 每个对象都具有描述其特征的属性,及附属于它的行为。

  14. 对象的三要素 接到大学通知书、被车碰了 属性 姓名 性别 国籍 出生日期 …… 身高 体重 血型 事件 狂奔 … 哭 笑 骂 方法

  15. 对象的三要素 属性(Attribute) 描述对象特征。 事件(Event) 外部实体作用在对象上的一个动作。 方法(Method) 事先设计好的,可以完成一定动作的过程程序。

  16. 2类(Class) 类是一种对象的归纳和抽象。类就像是一个图纸或一个模具,所有对象均是由它派生出来的,它确定了由它生成的对象所具有的属性、事件和方法。

  17. 表单设计的基本步骤 1. 表单规划。 2. 新建表单(建立数据环境) 3. 加入控件设置属性。 4. 设计事件代码。 5. 运行、修改直到满意为止。

  18. 表单对象 表单就是一个容器,它可以容纳多个控件。 用表单设计器创建表单 CREATE FORM <表单>.SCX 修改表单 MODIFY FORM <表单>.SCX 运行表单 DO FORM <表单>.SCX

  19. 控 件

  20. 表单实例

  21. 控件属性

  22. 常见事件

  23. 1.Release方法 将表单从内存释放。 例“退出”按钮的click事件代码设置为thisform.release。 2.Refresh方法 重新绘制表单和控件,并刷新值。 3.Show方法 显示表单。使表单的visible=.T. 4.Hide方法 隐藏表单。将表单的visible=.F. 5.Setfocus方法 让控件获得焦点,使其活动。 常用方法

  24. x = val(thisform.text1.value) if x<2 y=5 else y = (x+0.1-2)*1.4 endif thisform.text2.value=alltrim(str(y,10,1)) thisform.refresh 出租车计价器程序

  25. 对象引用 (1) 通常用以下引用关键字开头: THISFORM 表示当前表单 THIS 表示当前对象 (2) 引用格式: 引用关键字(.被引用对象).属性/事件/方法程序。 例如:THIS.Caption THISFORM.Command1.Caption (3) 控件也可引用包含它的容器,格式为: Control.Parent 其中Control表示控件, Parent表示容器。 例如THIS.Parent.Command1.Caption,表示引用本对象的容器(例如表单)的Command1命令按钮的Caption属性。

  26. 实验作业 分别以自定义函数和过程两种方法改写组合公式程序。 P232习题1。 P196例11.1

  27. 下节内容: • 复习两本书

More Related