当前位置:文档之家› VB大作业

VB大作业

语句3 Else
2
VB 程序设计教案
语句N End if 4 select case语句 5 提供简单选择的控件(单选钮optionbutton , 复选框checkbox)程序举例 例一:某航空公司规定在旅游旺季7-9月份,如果订票超过20张,票价优惠15%,20张以下,优惠5%; 在旅游淡季1-5月份,10月份,11月份,如果定票超过20张,票价优惠30%,20张以下,优惠20%;其他 情况一律优惠10%.
private sub command1_click() dim m as integer, n as intger, r as integer m=val(text1.text) n=val(text2.text) select case m case is<=5,10,11 if n<20 then r=20 else r=30 case 7 to 9 if n<20 then r=5 else r=15 case else r=10 end select label4.caption="所订票的优惠率为:" & str(r) & "%" end sub private sub form_Load() text1.text=month(date) end sub private sub text1_gotfocus() text1.selstart=0 text1.selength=len(text1.text)
(2) if (条件) then 语句序列1 else 语句序列2 (3) iif(条件,语句序列1,语句序列2) 2 块结构条件语句 if (条件) then
语句序列1 else 语句序列2 end if 3 if的嵌套结构 If (条件1) then
语句1 Elseif (条件2) then
语句2 Elseif (条件3) then
(3)设计个人资料输入窗口,信息要多样化。(使用选项按钮)
(4)编写程序,用文本框检查用户口令,利用文本框的PASSWORDCHAR属性
(件为列表框和组合框)
VB常用系统函数:
Sin() cos() sqr() log()
exp()=ex
Ltrim() :删除串中左端空格
(2)for i=2 to 10 step 2 循环体语句
VB 程序设计教案
private sub command1_click() if text1.text="" then a=inputbox("您忘记输入姓名!","注意","请在此输入姓名") if a="" or a="请在此输入姓名" then exit sub text1.text=a endif p1=text1.text+"," p2=iif(option1,"男","女")+”,” p3=iif(option3,"汉族","少数民族") p4=",喜欢:" if check1.value=1 then p4=p4+check1.caption+"、" if check2.value=1 then p4=p4+check2.caption+"、" if check3.value=1 then p4=p4+check3.caption+"、" if check4.value=1 then p4=p4+check4.caption+"、" aa=p1+p2+p3+iif(p4=",喜欢:",",无爱好。",p4) label4.caption=left(aa,len(aa)-1)+"。" text1.setfocus
private sub command1_click() dim as as single, y as single dim x1 as single,x2 as single dim x3 as single, x5 as single a=val(text1.text) x1=0.0225: x2=0.0243 : x3= 0.027 : x5=0.0288 select case true case option1.value y=(1+5*x5)*a case option2.value y=(1+3*x3)*(1+2*x2)*a case option3.value y=(1+3*x3)*(1+2*x2)^2*a case option4.value y=(1+2*x2)^2*(1+x1)*a case option5.value y=(1+2*x2)*(1+x1)^3*a case option6.value y=(1+x1)*^5*a
rtrim():删除串中右端空格
trim(): 删除串中前后端空格
randomize()语句:产生随机数的种子
rnd函数:产生0-1之间的随机数
rnd函数产生0-1之间的随机数,为了生成某个范围内的随机值,可以使用公式:int((最大值-
最小值+1)*rnd+最小值)
1循环的基本结构
(1)do while 条件 循环体语句 loop
6
end sub private sub text1_change() label4.caption="" end sub
VB 程序设计教案
上机作业: (1)输入X的值,求Y的值。
3x4-5x
x<-5
Y= 7x2 4x 5 +log(x2)
x>5
1-2sin(x)
-5<=x<=5
组输入选项)
(2)使用图形选项按钮组控制流动字幕中的字体
& ",球的表面积是:" & foramt(f,"####.##") & "." ,1+64+0,"计算圆的半径,球的体积和表面
积.")
作业(一):
(1) 利用输入框输入摄氏温度,求华氏温度.
(2)"鸡兔同笼"问题,鸡有2只脚,兔有4只脚,已知鸡和兔的总头数h,总脚数f,问笼中鸡,兔各有多
少只?(integer)
5
end select text2.text=y text1.setfocus end sub private sub text1_gotfocus() text1.selstart=0 text1.sellength=len(text1.text) end sub 2使用图形选项按钮组控制流动字幕中的字体. privat sub option1_click() text1.fontname="宋体" end sub >>>>>> 3设计一个个人资料输入窗口,使用选项按钮组输入一个或多个选项.
4
VB 程序设计教案
if label1.left+label1.width>0 then label1.move label1.left-20 else label1.left=form1.scalewidth end if end sub 例三 提供简单选择的控件(单选钮optionbutton , 复选框checkbox)程序举例 1设银行定期存款年利率为:1年期,2年期,3年期,5年期.今有本金A元,5年后使用,共有6中存法: (1)存1次5年期 (2)存1次3年期,存1次2年期 (3)存1次3年期,存2次1年期 (4)存2次2年期,存1次1年期 (5)存1次2年期,存3次1年期 (6)存5次1年期
3
VB 程序设计教案
end sub private sub text1_keypress(keyascii as integer) if keyascii=13 then if text1.text>0 and text1.text<13 then text2.setfocus end if end if end sub private sub text2_gotfocus() text2.selstart=0 text2.sellength=len(text2.text) end sub privat sub text2_keypress(keyascii as integer) if keyascii=13 then if text2.text>0 then command1.setfocus end if end sub 例二 使用计时器控件设计一个流动字幕板,标题"欲穷千里目,更上一层楼!"在窗体中自右至左 的反复移动. 计时器控件可以在应用中以重复的时间间隔产生一个事件.
Caption :&S 暂停 含义为:使得S字母下方显示下划线,并且成为一个热键:当从键盘上键入 《ALT》+S时候,相当于用鼠标单击该命令按钮。 time1: interval:100 enabled: false private sub command1_click() if command1.caption="&S 暂停" then command1.caption="&C 继续" timer1.enabled=false else command1.caption="&S 暂停" timer1.enabled=true end if end sub private sub time1_timer()
相关主题