3.
(1)a()AsDouble,nAsInteger
(2)t=t*x(3)f=s
五、程序设计题
程序1.界面设计略,过程设计如下:
PrivateFunctionfsum(x()AsDouble,nAsInteger)AsDouble
DimiAsInteger
Fori=1Ton
fsum=fsum+x(i)
Nexti
fsum=fsum/n
EndFunction
程序2.界面设计略,过程设计如下:
PrivateSubff(a()AsSingle,nAsInteger)
DimiAsInteger,xAsSingle
Fori=1Ton\2
x=a(n-i+1):
a(n-i+1)=a(i):
a(i)=x
Nexti
EndSub
程序3.界面设计略,过程设计如下:
PrivateSubfind(x()AsSingle,mAsbyte,nAsByte,_
xmaxAsSingle,kiAsByte,kjAsByte)
xmax=x(1,1):
ki=1:
kj=1
Fori=1Tom
Forj=1Ton
IfAbs(x(i,j))>Abs(xmax)Thenxmax=x(i,j):
ki=i:
kj=j
Nextj,i
EndSub
第5章常用控件
四、程序阅读题
程序1.116程序2.8
程序3.23451程序4.小,你好!
程序5.您好
34512小李,你好!
欢迎使用VisualBasic!
程序6.李子程序7.y=6程序8.n=1
苹果y=14n=3
橘子n=5
葡萄
柚子
香蕉
五、程序填空题
1.
(1)a(i)=Mid(str1,i,1)或a(i)=Mid(Text1.Text,i,1)
(2)p=j(3)a(i)=a(p)(4)Command2.Enabled=True
2.
(1)1To2*i–1
(2)Command2.Enabled=True(3)Command2.Enabled=False
3.
(1)Text2.Enabled=False
(2)p=2(3)Printi
(4)Val(Text1.Text)<2或Val(Text1.Text)<=1(5)KeyAscii=13
4.
(1)List1.ListCount
(2)List1.RemoveItemI(3)i=i+1
5.
(1)Timer1.Enabled=True
(2)x\3600
(3)(xMod3600)\60或(x-3600*h)\60(4)x=x+1
6.
(1)Label1.Left
(2)Label1.Left=-Label1.Width
六、程序设计题
程序1.界面设计略,过程设计如下:
PrivateSubCommand1_Click()
IfCommand1.Caption="显示"Then
Print"欢迎使用VisualBasic!
":
Command1.Caption="清除"
Else
Form1.Cls:
Command1.Caption="显示"
EndIf
EndSub
PrivateSubCommand2_Click()
End
EndSub
PrivateSubForm_Load()
Form1.Cls:
Command1.Caption="显示":
Command2.Caption="退出"
EndSub
程序2.界面设计略,过程设计如下:
PrivateSubForm_Load()
Text1.MaxLength=1:
Text1.Text=""
EndSub
PrivateSubText1_KeyPress(KeyAsciiAsInteger)
Label1.Caption=CStr(KeyAscii)
EndSub
程序3.界面设计略,过程设计如下:
ConstpwdAsString="123456"'预设密码为123456
PrivateSubCommand1_Click()
Cls:
Print"欢迎进入!
"
EndSub
PrivateSubForm_Load()
Command1.Caption="进入":
Command1.Enabled=Falsew
Text1.Text="":
Text1.PasswordChar="*"
EndSub
PrivateSubText1_KeyPress(KeyAsciiAsInteger)
IfKeyAscii=13Then
IfText1.Text=pwdThen
m=MsgBox("口令正确,欢迎进入!
"):
Command1.Enabled=True
Else
m=MsgBox("口令错误,请重新输入!
"):
Text1.Text=""
EndIf
EndIf
EndSub
程序4.界面设计略,过程设计如下:
DimnumAsInteger,mAsInteger,recAsInteger
PrivateSubForm_Load()
Command1.Caption="出题":
Command1.Enabled=True
Text1.Text="":
Text1.Enabled=False:
rec=0
EndSub
PrivateSubCommand1_Click()
Randomize:
num=Int(Rnd*100)+1:
Text1.Enabled=True
Label1.Caption="":
Command1.Enabled=False
EndSub
PrivateSubCommand2_Click()
End
EndSub
PrivateSubText1_KeyPress(KeyAsciiAsInteger)
IfKeyAscii=13Then
m=Val(Text1.Text):
rec=rec+1:
Text1.SelStart=0
Text1.SelLength=Len(Text1.Text):
Text1.SetFocus
Ifrec>10Then
Label1.Caption="差!
重新开始":
CallForm_Load
Else
Ifm>numThen
Label1.Caption=Str(m)&"大了!
"
ElseIfmLabel1.Caption=Str(m)&"小了!
"
Else
Ifrec<5Then
Label1.Caption="好!
猜对了。
"
Else
Label1.Caption="还行!
猜对了。
"
EndIf
CallForm_Load
EndIf
EndIf
EndIf
EndSub
程序5.界面设计如图10-3所示,过程设计如下:
PrivateSubForm_Load()
Command1(0).Enabled=False:
Command1
(1).Enabled=False
Command1
(2).Enabled=False:
Label1.Caption=""
EndSub
PrivateSubCommand1_Click(IndexAsInteger)
SelectCaseIndex
Case0
Clipboard.Clear:
Clipboard.SetTextText1.SelText
Text1.SelText="":
Label1.Caption="请选择要粘贴的位置!
"
Command1(0).Enabled=False:
Command1
(1).Enabled=False
Command1
(2).Enabled=True
Case1
Clipboard.Clear:
Clipboard.SetTextText1.SelText
Label1.Caption="请选择要粘贴的位置!
":
Command1(0).Enabled=False
Command1
(1).Enabled=False:
Command1
(2).Enabled=True
CaseElse
Text1.SelText=Clipboard.GetText():
Form_Load
Label1.Caption="粘贴完成!
"
EndSelect
EndSub
PrivateSubText1_MouseUp(ButtonAsInteger,ShiftAsInteger,_
XAsSingle,YAsSingle)
DimnAsInteger
n=Text1.SelLength
Ifn>0Then
Label1.Caption="选择了"&n&"个字,请选择下一步操作!
"
Command1(0).Enabled=True:
Command1
(1).Enabled=True
Else
Label1.Caption=""
EndIf
EndSub
程序6.界面设计如图10-4所示,过程设计如下:
PrivateSubForm_Load()
Label1.Caption="当前日期:
":
Text1.Text=Date
Option1(0).Caption="显示日期":
Option1
(1).Caption="显示时间"
Option1(0).Value=True:
Command1.Caption="退出"
EndSub
PrivateSubOption1_Click(IndexAsInteger)
SelectCaseIndex
Case0
Label1.Caption="当前日期:
":
Text1.Text=Date
Case1
Label1.Caption="当前时间:
":
Text1.Text=Time
EndSelect
EndSub
PrivateSubCommand1_Click()
End
EndSub
程序7.过程设计如下:
PrivateSubForm_Load()
Label1.Caption="当前日期:
":
Text1.Text=Date
Option1(0).Caption="显示日期":
Option1
(1).Caption="显示时间"
Option1(0).Value=True:
Command1.Caption="退出"
Combo1.AddItem"年-月-日":
Combo1.AddItem"月-日-年"
Combo1.AddItem"日-月-年":
Combo1.Text="年-月-日"
EndSub
PrivateSubCombo1_Click()
DimnAsString
SelectCaseCombo1.ListIndex
Case0:
n="yyyy-mm-dd"
Case1:
n="mm-dd-yyyy"
Case2:
n="dd-mm-yyyy"
EndSelect
Text1.Text=Format(Date,n)
EndSub
PrivateSubOption1_Click(IndexAsInteger)
SelectCaseIndex
Case0:
Label1.Caption="当前日期:
":
Text1.Text=Date
Case1:
Label1.Caption="当前时间:
":
Text1.Text=Time
EndSelect
EndSub
PrivateSubCommand1_Click()
End
EndSub
程序8.界面设计如图10-5所示,过程设计如下:
PrivateSubForm_Load()
List1.AddItem"happy":
List1.AddItem"apple"
List1.AddItem"student":
List1.AddItem"computer"
EndSub
PrivateSubCommand1_Click()