a(i)=a(j):
a(j)=t
Nextj
Nexti
Fori=1To10
Printa(i);
Nexti
EndSub
4、
PrivateSubForm_Click()
Dima(100)AsInteger,score(5)AsInteger
Fori=1To100
a(i)=Int(Rnd*66)+35
Printa(i);
Nexti
Print
Fori=1To20
Ifa(i)>=90Then
score
(1)=score
(1)+1
ElseIfa(i)>=80Then
score
(2)=score
(2)+1
ElseIfa(i)>=70Then
score(3)=score(3)+1
ElseIfa(i)>=60Then
score(4)=score(4)+1
Else
score(5)=score(5)+1
EndIf
Nexti
Fori=1To5
Printscore(i)
Nexti
EndSub
P182练习五
一.对:
1,2,3,4,6,7,9
错:
5,8
二.1,D2,C3,A4,B5,D6,A7,(全错)8,D
三.
1,DDBB
2,
1)Int(Rnd*21)+30
2)Forj=i+1To10
3)CallSwap(a(i),a(j))
4)a(10)
3,
1)IfIsprime(i)AndIsprime(x-i)Then
2)Isprime=True
3)IfxModi=0Then
四,
1.976
2,4
-9
3,646
483642
4,26
9
五,
1、
PrivateSubCommand1_Click()
Dima()AsSingle,nAsInteger,sAsSingle
DimvAsSingle,iAsInteger
n=InputBox("请输入n的值")
ReDima(n)
Fori=1Ton
a(i)=InputBox("")
Nexti
v=f(a,n)
Fori=1Ton
s=s+(a(i)-v)^2
Nexti
s=Sqr(s)/n
Prints
EndSub
2,
Privatefunctionfsum(x()AsSingle,mAsbyte)assingle
fsum=x
(1)
Fori=2Tom
Fsum=fsum+x(i)
NextI
Endfunction
P213练习六
一,单选题
1,A2,A3,C4,C5,C6,B7,A8,A
二,阅读题
1.代码1
代码2
2,
3.
4.
5.
三,程序设计题
1.
PublicSubRectangle(ByValaAsSingle,ByValbAsSingle,yAsSingle)
DimyAsSingle
y=a*b
EndSub
2.
PublicFunctionRound(ByValrAsSingle)AsSingle
Round=3.14159*r*r
EndFunction
P269书面练习7
二.程序阅读题
1,保存所有打开的工作簿,关闭ExceL
2,实现定时提醒,17:
00显示一个提醒信息。
3,查找工作表“KK”,若有,则结束过程,否则,在第一张工作
前添加工作表“KK”
4,
5.
6
6.把工作表指定区域的数化为以万为单位(输入小数位数)
7.在当前工作表的第2行以下第3列中输入或修改单元格内容,则自动转换
成“编号”工作表中A2以下A列中相同内容的单元格的右边单元格的内容。
3.程序设计题
1,
SubWorkbook_BeforeClose(CancelAsBoolean)
DimiAsInteger,jAsInteger,kAsString
Fori=66To68
Forj=3To12
k=Chr(i)&j
IfRange(k).Value<0OrRange(k).Value>100Then
Cancel=True
MsgBox"成绩应该在0~100之间,否则,不允许关闭工作簿!
"
EndIf
Nextj
Nexti
EndSub
2.
PrivateSubChFmt()
DimiAsLong,jAsLong
IfCells(i,j).Value<60AndCells(i,j).Value>0Then
Cells(i,j).Font.Color=RGB(255,0,0)
Cells(i,j).Font.Bold=True
EndIf
Nextj
Nexti
EndSub
3,
PrivateSubWorkbook_Open()
DimiAsInteger,jAsInteger
Fori=1To10
Forj=1To10
Worksheets("sheet1").Cells(i,j)=Int(Rnd()*90)+10
Nextj
Nexti
EndSub
Subbs6()
DimiAsInteger,jAsInteger,kAsInteger
k=1
Fori=1To10
Forj=1To10
IfWorksheets("sheet1").Cells(i,j)Mod6=0Then
Worksheets("sheet2").Cells(k,1)=Worksheets("sheet1").Cells(i,j)
k=k+1
EndIf
Nextj
Nexti
EndSub
4,
Subzz()
DimiAsInteger,jAsInteger
DimmAsInteger,nAsInteger
m=InputBox("")
n=InputBox("")
Fori=1Tom
Forj=1Ton
Worksheets("sheet1").Cells(i,j)=Int(Rnd()*90)+10
Nextj
Nexti
Fori=1Tom
Forj=1Ton
Worksheets("sheet2").Cells(j,i)=Worksheets("sheet1").Cells(i,j)
Nextj
Nexti
EndSub
P311书面练习八
一.判断题
对:
1,5,6,7,9,10
错:
2,3,4,8
二.程序填空题
1,
PrivateSubWorkbook_Open()
frmstart.Show
EndSub
PrivateSubclosestart()
UnloadMe
EndSub
第1段代码应写在Thisworkbook模块里
第3段代码写在模块里
2,
Cells(i,1)
Loop
三,编程题
PrivateSubShowTime()
'定义"显示时间"按钮事件
MsgBoxNow
EndSub
PrivateSubWelcome()
'定义"显示欢迎"按钮事件
MsgBox"感谢您使用自定义菜单"
EndSub
PrivateSubsheetCount()
'定义"显示工作表数"按钮事件
DimisheetcountAsInteger
isheetcount=Worksheets.Count
MsgBoxisheetcount
EndSub
SubShowProduct()
'显示本文档的文件名
MsgBoxThisWorkbook.Name
EndSub
PublicSubCreateToolbar()
'创建工具栏
OnErrorResumeNext
CommandBars("ManageData").Delete
OnErrorGoTo0
'下面代码用于创建工具栏中的按钮及关联事件
WithCommandBars.Add(Name:
="ManageData")
With.Controls.Add(Type:
=msoControlButton)
.OnAction="ShowDataForm"
.FaceId=264
.TooltipText="显示时间"
EndWith
With.Controls.Add(Type:
=msoControlPopup)
.Caption="操作按钮"
.TooltipText="选项"
With.Controls.Add(Type:
=msoControlButton)
.Caption="显示产品"
.FaceId=210
.OnAction="ShowProduct"
EndWith
With.Controls.Add(Type:
=msoControlButton)
.Caption="显示工作表数"
.FaceId=210
.OnAction="SortList"
EndWith
EndWith
With.Controls.Add(Type:
=msoControlDropdown)
.AddItem"10"
.AddItem"20"
.AddItem"50"
.AddItem"100"
.OnAction="zoomSize"
.TooltipText="视图显示比例"
EndWith
.Visible=True
EndWith
EndSub
'下面用于响应"视图显示比例"事件
SubzoomSize()
DimstDeptAsString
WithCommandBars.ActionControl
stDept