下载
加入VIP
  • 专属下载特权
  • 现金文档折扣购买
  • VIP免费专区
  • 千万文档免费下载

上传资料

关闭

关闭

关闭

封号提示

内容

首页 vb程序设计教程参考答案

vb程序设计教程参考答案.doc

vb程序设计教程参考答案

一转眼回头便苍老
2013-11-28 0人阅读 举报 0 0 暂无简介

简介:本文档为《vb程序设计教程参考答案doc》,可适用于高等教育领域

第一章、B、A、B、答:属性:红色、充满氢气事件:松手、针刺方法:飞走、爆破。、答:事件是指对象能够识别并作出反映的外部刺激。事件驱动又称消息驱动事件驱动程序设计是指每个事件对应有相应的程序代码仅在该事件发生时该段代码才会被执行。事件发生的顺序决定了代码执行的顺序因此每次执行应用程序时程序代码并不是按照程序编写的顺序来执行的。、答:VB是一个包括界面设计、程序编码、调试、编译并创建可执行程序的集成开发环境。VB的集成开发环境的主界面中包含:标题栏、菜单栏、工具栏、控件箱、工程资源管理器、属性窗口、“窗体布局”窗口、窗体设计器、代码编辑器等元素组成。、答:VB菜单条通常情况下有:文件、编辑、视图、工程、格式、调试、运行、查询、图表、工具、外接程序、窗口、帮助等项菜单项组成。、答:工具栏可自行定义。标准工具栏中通常情况下有:添加标准exe工程、添加窗体、菜单编辑器、打开工程、保存工程、剪切、复制、粘贴、查找、撤消、重复、启动、中断、结束、工程资源管理器、属性窗口、窗体布局窗口、对象浏览器、工具箱、数据视图窗口、可视化元件管理器等按钮组成。、答:创建VB应用程序的一般步骤为:创建界面设置窗体和控件属性编写代码保存工程运行并调试程序检查并排除错误创建可执行文件。PrivateSubCommandClick()LabelCaption="Ilovevb,Ihatevb"EndSub第二章、、、S输入待判断自然数:N(N>=)Si=S判断i是否小于N若不是转SS判断N除以i的余数是否为,如果不是则i=i转SS判断i是否等于N若是输出“是素数”否则输出“不是素数”。、S输入待判断自然数:NS将N转换成字符S计算S的长度KSi=S判断i是否小于K若不是转SS判断S中的第i位和第Ki位是否相等,如果是则i=i转S如果不是则转SS判断i是否是中间位数若是输出“是回文数”否则输出“不是回文数”。、S输入待判断自然数:aSi=S判断i是否小于a若不是转SS判断a除以i的余数是否为,如果是则保留因子i否则i=i转SS输出所有因子。、第三章、窗体的属性主要分为杂项、外观、行为、字体、位置等五类。Caption是窗体标题出现在窗体标题栏的文本内容而Name是窗体名称在程序代码中被作为窗体的标识名。、ABDE、改变窗口的工作状态会引发Activate事件改变窗口大小会引发resize事件。、forecolor和backcolor属性首先选择系统中的选项然后在调色板中设置相应的颜色font属性设置好以后在窗体上放置的任何控件都会继承窗体的font属性。、C、Label、optionbutton、checkbox、commandbutton有caption属性没有text属性text、combobox有text属性没有caption属性、对象的属性可以在设计界面时在属性窗口中和运行中在代码中设置属性窗口中的属性列表并没有包括对象的所有属性。、picturebox、frame等、optionbutton和checkbox。Optionbox的Value可以取true-选中和false-未选中checkbox的Value可以取-未选中-选中-变灰表示暂时不能访问。、text、commandbutton可以获得焦点。在设计界面时第一个放在窗体上的文本框或命令按钮将得到焦点。、C、把Value的值设为表示暂时不能访问复选框点击复选框后就可以访问了而把enabled属性设为false则是复选框变灰完全不能访问。若把一个控件的Visible属性设为false则在程序运行时看不到该控件。、用additem来添加列表项用removeitem删除已有的列表项用clear删除所有列表项。、、PrivateSubCheckClick()IfCheckValue=ThenLabelFontItalic=TrueElseIfCheckValue=ThenLabelFontItalic=FalseEndIfEndSubPrivateSubCheckClick()IfCheckValue=ThenLabelFontBold=TrueElseIfCheckValue=ThenLabelFontBold=FalseEndIfEndSubPrivateSubCommandClick()EndEndSubPrivateSubOptionClick()IfOptionValueThenLabelFontSize=LabelRefreshEndSubPrivateSubOptionClick()IfOptionValueThenLabelFontSize=LabelRefreshEndSubPrivateSubOptionClick()IfOptionValueThenLabelFontSize=LabelRefreshEndSubPrivateSubOptionClick()IfOptionValueThenLabelFontName="宋体"LabelRefreshEndSubPrivateSubOptionClick()IfOptionValueThenLabelFontName="隶书"LabelRefreshEndSubPrivateSubOptionClick()IfOptionValueThenLabelFontName="黑体"LabelRefreshEndSub、、第四章B见教材P不对通用过程也可以存在于窗体模块中见教材P字符串型常量的界定符是双引号"日期型数据的界定符是磅号#。A、B是字符型C、D是日期型E、F不属于任何类型。合法变量名有:A、C、D(VB中合法变量名只能由字母、数字和下划线构成并且只能以字母开头)见教材P()a(bcd)()(sqr(x^)x)^()()(*y)((a*xb*y)*(a*xb*y))()(m)()(d)^(*x)()log(ycos(x)^)()fabs((exp(x)sin(x)^)(xy))()log((exp(x*y)fabs(tan(z)^cos(x)^))(xyz))()()(AB)(AB)()()A*B*C((D)*Y)()()(X*Y)^Axy<andxy>Bx*y>andx=fix(x)andy=fix(y)CA=XORB=DCCC>=andC>andC>andC>TFFFFBCDE(A会发生溢出的错误)()""()()""()()""()()""()以为底的X的对数:log(x)log()z=Inputbox("输入一个数:""程序示例")Msgbox"Z的值大于""程序示例"OptionExplicitConstPIAsSingle=PrivateSubCommandClick()DimaAsSingle,bAsSingle,cAsSingle,areaAsSinglea=Val(TextText)b=Val(TextText)c=Val(TextText)*PI'角度角转换为弧度角area=a*b*Sin(c)Text=CStr(Format(area,""))'使纯小数能出现整数位的EndSubPrivateSubCommandClick()TextText=""TextText=""TextText=""EndSubPrivateSubCommandClick()EndEndSub第五章OptionExplicitPrivateSubCommandClick()DimaAsInteger,bAsIntegera=:b=DoWhilea<=b=ba*aa=aLoopPrinta,bEndSubPrivateSubCommandClick()DimchAsString,iAsIntegerch="DEF"Fori=ToLen(ch)'循环的上界不会变ch=Mid(ch,*i,)Left(ch,Len(ch))PrintchNextiEndSubPrivateSubCommandClick()DimpAsInteger,iAsIntegerp=Fori=Top=p(*i)(*i)Ifp>=ThenExitFor'跳出循环前执行不到这一句NextiPrinti,pEndSubPrivateSubCommandClick()DimpAsInteger,iAsInteger,nAsIntegerp=:n=Fori=TonStepp'计数循环的初值、终值和步长都不会变p=pn=ni=iIfp>=ThenExitForNextiPrinti,p,nEndSubOptionExplicitDimnAsInteger,nAsInteger,nAsIntegerPrivateSubCommandClick()DimiAsInteger,jAsInteger,kAsIntegerFori=ToForj=Tok=Int(Rnd*)PrintkIfk<=Thenn=nElseIfk<=Thenn=nElsen=nEndIfNextjPrintNextiEndSubPrivateSubCommandClick()Print"小于等于的数据个数为:"n"个"Print"大于小于等于的数据个数为:"n"个"Print"大于的数据个数为:"n"个"EndSubPrivateSubCommandClick()ClsEndSubOptionExplicitPrivateSubCommandClick()DimxAsInteger,yAsIntegerx=TextTextIfx<=Theny=xElseIfx<=Theny=xElseIfx<=Theny=x^Elsey=xEndIfTextText=yEndSubPrivateSubCommandClick()TextText=""Text=""EndSubOptionExplicitPrivateSubCommandClick()DimiAsInteger,jAsInteger,kAsIntegerFori=ToForj=Tok=Int(Rnd*)PicturePrintkIfkMod<>ThenListAddItemkElseListAddItemkEndIfNextjPicturePrintNextiEndSubOptionExplicitPrivateSubCommandClick()DimmAsInteger,nAsInteger,rAsIntegerm=Val(TextText)n=Val(TextText)Dor=mModnIfr<>Thenm=nn=rElseExitDoEndIfLoopTextText=Val(TextText)*Val(TextText)nEndSubOptionExplicitDimrAsInteger,rAsSingle'r可能是个很大的数最好定义成单精度型PrivateSubCommandClick()DimiAsInteger,kAsIntegerr=:r='r一定要初始化为否则积为Fori=Tok=InputBox("请输入第"i"个数")PicturePrintkr=rkr=r*kNextiEndSubPrivateSubCommandClick()Text=rEndSubPrivateSubCommandClick()Text=rEndSubOptionExplicitPrivateSubCommandClick()DimsAsString,sAsString,sAsString,iAsIntegers=TextTextFori=ToLen(s)s=Mid(s,i,)Ifs>=""Ands<=""Thens=ssEndIfNextiTextText=sEndSubOptionExplicitPrivateSubCommandClick()Text=""Text=""EndSubPrivateSubCommandClick()DimnAsInteger,rAsString,sAsStringn=Val(TextText)Dor=nMods=rsn=nLoopUntiln='当商为时则跳出循环TextText=sEndSubOptionExplicitPrivateSubCommandClick()DimaAsLong,bAsLong,cAsLongFora=ToForb=ToForc=ToIfa*ab*b=c*cThenListAddItema","b","cEndIfNextcNextbNextaEndSubOptionExplicitPrivateSubCommandClick()DimiAsInteger,rAsInteger,rAsInteger,rAsIntegerFori=Tor=ir=(i)Mod'或者r=(imod)r=(iMod)ModIfr<rAndr<rThenListAddItemiEndIfNextiEndSubOptionExplicitPrivateSubCommandClick()DimaAsSingle,bAsSingle,cAsSinglea=:b=c=(ab)DoIff(a)*f(c)>Thena=cElseb=cEndIfc=(ab)LoopUntilAbs(bc)<=TextText=Format(c,"########")EndSubPrivateFunctionf(xAsSingle)AsSinglef=x^x^*x^EndFunction第六章请同学上机运行代码。OptionExplicitOptionBasePrivateSubCommandClick()DimiAsInteger,tAsIntegerDima()AsIntegerRandomizeFori=Toa(i)=Int(*Rnd)Text=TextStr(a(i))NextiFori=Tot=a(i)a(i)=a(i)a(i)=tNextiFori=ToText=TextStr(a(i))NextiEndSubPrivateSubCommandClick()Text=""Text=""EndSubPrivateSubCommandClick()EndEndSubOptionExplicitDima()AsIntegerPrivateSubCommandClick()DimiAsIntegerRandomizeFori=Toa(i)=Int(*Rnd)Text=TextStr(a(i))NextiEndSubPrivateSubCommandClick()DimiAsInteger,jAsInteger,fAsBooleanDimnAsIntegerFori=Tof=TrueForj=iToIfa(i)=a(j)Thenf=FalseNextjIff=TrueThenn=nNextiText=nEndSubPrivateSubCommandClick()Text=""EndSubPrivateSubCommandClick()EndEndSubOptionExplicitDima()AsIntegerPrivateSubCommandClick()DimiAsIntegerRandomizeFori=Toa(i)=Int(*Rnd)Text=TextStr(a(i))NextiEndSubPrivateSubCommandClick()DimiAsInteger,jAsInteger,maxAsIntegerDimnAsInteger,wAsInteger,pAsIntegerFori=Ton=:p=iForj=ToIfi>Thenp=pn=na(p)NextjIfn>maxThenmax=nw=iEndIfNextiText=maxPicturePrintw""wEndSubPrivateSubCommandClick()Text=""EndSubPrivateSubCommandClick()EndEndSubDima(,)AsIntegerPrivateSubCommandClick()Fori=ToForj=Toa(i,j)=Int(*Rnd)PicturePrinta(i,j)NextjPicturePrintNextiEndSubPrivateSubCommandClick()Forj=Tos=Fori=Tos=sa(i,j)NextiText=TextStr(s)NextjEndSubPrivateSubCommandClick()Fori=Tos=Forj=Tos=sa(i,j)NextjText=TextStr(s)Chr()Chr()NextiEndSubPrivateSubCommandClick()Text=""Text=""PictureClsEndSubPrivateSubCommandClick()EndEndSubOptionExplicitPrivateSubCommandClick()Dima(,),iAsInteger,jAsIntegerDimnAsInteger,mAsInteger,tAsIntegerRandomizeFori=ToForj=Toa(i,j)=Int(*Rnd)*NextjNextiFori=ToForj=ToiStepa(i,j)=Int(*Rnd)*NextjNextiFori=ToForj=ToText=TextStr(a(i,j))NextjText=TextvbCrLfNextiEndSub同Dima(,)AsIntegerPrivateSubCommandClick()RandomizeFori=ToForj=Toa(i,j)=Int(*Rnd)PicturePrintRight(""a(i,j),)NextjPicturePrintNextiEndSubPrivateSubCommandClick()Fori=ToForj=Tos=sa(i,j)NextjNextiText=Str(s)EndSubPrivateSubCommandClick()Fori=ToForj=ToIfi=Orj=Ori=Orj=Thens=sa(i,j)EndIfNextjNextiText=Str(s)EndSubPrivateSubCommandClick()Fori=ToForj=ToIfi=jOrj=iThens=sa(i,j)EndIfNextjNextiText=Str(s)EndSubOptionExplicitPrivateSubCommandClick()Dima()AsInteger,iAsInteger,jAsIntegerDimmaxAsInteger,kAsInteger,fAsBooleanDimnAsInteger,mAsInteger,tAsIntegern=InputBox("输入矩阵的行数:")m=InputBox("输入矩阵的列数:")ReDima(n,m)RandomizeFori=TonForj=Toma(i,j)=Int(*Rnd)Text=TextStr(a(i,j))NextjText=TextvbCrLfNextiFori=Tonmax=Forj=TomIfa(i,j)>maxThenmax=a(i,j)t=jEndIfNextjFork=TonIfa(k,t)<maxThenExitForNextkIfk>nThenPicturePrint"鞍点:"a(i,t)"第"i"行"t"列"f=TrueEndIfNextiIff=FalseThenPicturePrint"没有鞍点"EndSubPrivateSubCommandClick()Text=""PictureClsEndSubPrivateSubCommandClick()EndEndSubOptionExplicitPrivateSubFormClick()Dima()AsInteger,nAsIntegerDimiAsInteger,jAsIntegern=InputBox("层数")ReDima(n,n)Fori=TonPrintTab(*i)Forj=ToiIfi=Ori=jThena(i,j)=Elsea(i,j)=a(i,j)a(i,j)EndIfPrintLeft(a(i,j)"",)NextjPrintNextiEndSubOptionExplicitPrivateSubCommandClick()Dima(,),iAsInteger,jAsIntegerDimb()AsInteger,maxAsInteger,minAsIntegerDimnAsInteger,mAsInteger,tAsIntegerRandomizemax=:min=Fori=ToForj=Toa(i,j)=Int(*Rnd)Text=TextStr(a(i,j))b(i)=b(i)a(i,j)NextjText=TextvbCrLfIfmax<b(i)Thenmax=b(i):m=iElseIfmin>b(i)Thenmin=b(i):n=iEndIfNextiLabelCaption="max行和:"max"min行和:"minvbCrLf"max行:"m"min行:"n"交换这两行"Forj=Tot=a(m,j)a(m,j)=a(n,j)a(n,j)=tNextjFori=ToForj=ToText=TextStr(a(i,j))NextjText=TextvbCrLfNextiEndSubOptionExplicitPrivateSubCommandClick()Dima(),iAsInteger,jAsIntegerDimb()AsInteger,maxAsInteger,minAsIntegerDimnAsInteger,mAsInteger,tAsIntegerRandomizen=InputBox("矩阵阶数n:")ReDima(n,n)Fori=TonForj=Tona(i,j)=Int(*Rnd)Text=TextStr(a(i,j))NextjText=TextvbCrLfNextiFori=TonForj=TonText=TextStr(a(j,i))NextjText=TextvbCrLfNextiEndSubPrivateSubCommandClick()Text=""Text=""EndSubPrivateSubCommandClick()EndEndSubOptionExplicitOptionBasePrivateSubCommandClick()Dima(,)AsInteger,iAsInteger,jAsIntegerDimmaxAsLong,kAsLong,fAsIntegerDimnAsInteger,mAsIntegerRandomizeFori=ToForj=Toa(i,j)=Int(*Rnd)Text=TextStr(a(i,j))NextjText=TextvbCrLfNextiFori=To'主对角线方向m=ik=Forj=Tok=k*a(m,j)m=mIfm>Thenm=NextjIfk>maxThenmax=kn=if=EndIfNextiFori=To'辅对角线方向m=ik=Forj=Tok=k*a(j,m)m=mIfm<Thenm=NextjIfk>maxThenmax=kn=if=EndIfNextiPicturePrint"最大组元素:"Iff=ThenFori=ToPicturePrint"a("n","i")="a(n,i)""n=nIfn>Thenn=NextiPicturePrint"a("n","i")="a(n,i)ElseIff=ThenFori=ToPicturePrint"a("i","n")="a(i,n)""n=nIfn<Thenn=NextiPicturePrint"a("i","n")="a(i,n)EndIfPicturePrint"乘积="maxEndSubPrivateSubCommandClick()Text=""PictureClsEndSubPrivateSubCommandClick()EndEndSubOptionExplicitPrivateSubCommandClick()Dima(,)AsInteger,iAsInteger,jAsIntegerDimkAsIntegeri=:j=:a(i,j)=:k=DoUntilk>k=kIfi>Andj<=Theni=:j=jElseIfi<=Andj>Theni=i:j=ElseIfi>Andj>Theni=iElseIfi<=Andj<=Anda(i,j)<>Theni=iElsei=i:j=jEndIfa(i,j)=kLoopFori=ToForj=ToPicturePrinta(i,j)NextjPicturePrintNextiEndSubPrivateSubCommandClick()Dima()AsInteger,iAsInteger,jAsIntegerDimkAsIntegerDimnAsIntegern=InputBox("幻方阶数:")ReDima(n,n)i=n:j=(n):a(i,j)=:k=DoUntilk>n*nk=kIfi>nAndj<=nTheni=:j=jElseIfi<=nAndj>nTheni=i:j=ElseIfi>nAndj>nTheni=iElseIfi<=nAndj<=nAnda(i,j)<>Theni=iElsei=i:j=jEndIfa(i,j)=kLoopFori=TonForj=TonPicturePrintRight(""a(i,j),)NextjPicturePrintNextiEndSubOptionExplicitOptionBasePrivateSubCommandClick()Dima()AsInteger,iAsInteger,jAsIntegerDimmaxAsLong,kAsLong,fAsIntegerDimnAsInteger,mAsIntegerRandomize

用户评价(0)

关闭

新课改视野下建构高中语文教学实验成果报告(32KB)

抱歉,积分不足下载失败,请稍后再试!

提示

试读已结束,如需要继续阅读或者下载,敬请购买!

文档小程序码

使用微信“扫一扫”扫码寻找文档

1

打开微信

2

扫描小程序码

3

发布寻找信息

4

等待寻找结果

我知道了
评分:

/42

vb程序设计教程参考答案

VIP

在线
客服

免费
邮箱

爱问共享资料服务号

扫描关注领取更多福利