VB语言程序设计课后编程及上机调试参考答案

整理文档很辛苦,赏杯茶钱您下走!

免费阅读已结束,点击下载阅读编辑剩下 ...

阅读已结束,您可以下载文档离线阅读编辑

资源描述

1VB语言程序设计课后编程及上机调试参考答案ex0101PrivateSubLabel1_Click()Caption=练习Command1.Caption=确定Label1.FontBold=TrueLabel1.AutoSize=TrueLabel1.Caption=VisualBasic程序设计教程EndSubex0102PrivateSubCommand1_Click()Txt.Text=我有电脑EndSubPrivateSubCommand2_Click()Txt.Text=我没有电脑EndSubPrivateSubCommand3_Click()Txt.Text='一对双撇号,中间不留空EndSubex0104PrivateSubCommand1_Click()DimxAsSinglex=Val(Text1.Text)Text2.Text=15*xEndSubex0202PrivateSubForm_Click()DimrAsSingle,sAsSingler=4.6s=3.14159*r^2Text1.Text=圆的面积为&sEndSubex0204PrivateSubCommand1_Click()'最大化按钮Form1.WindowState=2'最大化EndSubPrivateSubCommand2_Click()'还原按钮Form1.WindowState=0'还原2EndSubPrivateSubCommand3_Click()'最小化按钮Form1.WindowState=1'最小化EndSubex0205PrivateSubcommand1_click()DimxAsSingleDimyAsSinglex=Val(Text1.Text)y=Val(Text2.Text)Text3.Text=x*x+y*yEndSubex0206PrivateSubcommand1_click()DimxAsStringx=Text1.TextText2.Text=Left(x,1)+Right(x,1)EndSubex0301PrivateSubForm_Load()DimxAsInteger,yAsIntegerDimaAsInteger,bAsInteger,cAsIntegerx=Val(InputBox(请输入一个三位数))a=Int(x/100)'求百位数b=Int(x/10)-a*10'求十位数c=xMod10'求个位数Showy=c*100+b*10+a'生成倒序数Printx;倒序数为:;y'显示倒序数EndSubex0302PrivateSubCommand1_Click()n=Val(Text1.Text)Randomizex=Int(1+n*Rnd)Label1.Caption=第一个随机数+Str(x)x=Int(1+n*Rnd)Label2.Caption=第二个随机数+Str(x)x=Int(1+n*Rnd)Label3.Caption=第三个随机数+Str(x)3EndSubex0303PrivateSubCmd1_Click()Lab1.Visible=TrueLab1.Caption=您已下达显示命令EndSubPrivateSubForm_Click()Cmd1.Visible=TrueEndSubex0304PrivateSubForm_KeyPress(KeyAsciiAsInteger)ShowPrint输入字符:;Chr(KeyAscii),ASCII码为;;KeyAsciiEndSubPrivateSubForm_DblClick()ClsEndSubex0305PrivateSubForm_Load()x=MsgBox(在这里显示提示信息,4+0,请确认)x=MsgBox(在这里显示+Chr(13)+提示信息,3+0,请确认)x=MsgBox(在这里显示+Chr(13)+提示信息,2+16+0,请确认)EndSubex0401PrivateSubForm_Load()DimxAsLong,sAsStringx=InputBox(输入一个整数(1~35000))s=奇数IfxMod2=0Thens=偶数MsgBoxsEndSubex0402PrivateSubCommand1_Click()DimaAsSingle,bAsSingleDimcAsSingle,dAsSingleDimmAsSingle,nAsSingle,xAsSingleShowa=Val(Text1.Text)b=Val(Text2.Text)4c=Val(Text3.Text)d=Val(Text4.Text)IfabThen'求a、b中的较大数m=aElsem=bEndIfIfcdThen'求c、d中的较大数n=cElsen=dEndIfIfmnThen'求m、n中的较大数x=mElsex=nEndIfText5.Text=xEndSubex0403PrivateSubCommand1_Click()DimtAsString,pAsStringt=Mid(Text1.Text,5,1)SelectCasetCase2p=博士生Case3p=硕士生Case4p=本科生Case5p=专科生CaseElsep=无效学号EndSelectText2.Text=Left(Text1.Text,2)+级Text3.Text=pEndSubex0404PrivateSubCommand1_Click()r=0:g=0:b=0IfCheck1.Value=1Then5r=255EndIfIfCheck2.Value=1Theng=255EndIfIfCheck3.Value=1Thenb=255EndIfLabel1.BackColor=RGB(r,g,b)EndSubPrivateSubCommand2_Click()EndEndSubex0405PrivateSubForm_Load()LabClk.Caption=0LabClk.Alignment=1LabClk.BorderStyle=1LabClk.FontSize=22LabClk.FontName=黑体TimClk.Interval=1000EndSubPrivateSubTimClk_Timer()LabClk.Caption=Val(LabClk.Caption)+1EndSubex0406PrivateSubForm_Load()Command1.Enabled=FalseCommand2.Enabled=FalseEndSubPrivateSubText1_MouseUp(ButtonAsInteger,ShiftAsInteger,XAsSingle,YAsSingle)IfText1.SelLength0ThenCommand1.Enabled=TrueEndIfEndSubPrivateSubCommand1_Click()Command1.Enabled=TrueCommand2.Enabled=TrueEndSubPrivateSubCommand2_Click()Text2.Text=Text1.SelTextCommand1.Enabled=False6Command2.Enabled=FalseEndSubex0501PrivateSubForm_Load()DimkAsInteger,sAsInteger,tAsIntegers=0Fork=1To100Step2s=s+kNextkShowPrint1~100范围内的奇数和:;sEndSubex0502PrivateSubForm_Load()DimsAsSingleShows=0Fork=1To200s=s+k/(1+k*k)NextkPrintInt(s*10+0.5)/10EndSubex0503PrivateSubForm_Load()Showk=2s=0DoWhilek101s=s+k*(k-1)k=k+2LoopPrintsEndSubex0504PrivateSubForm_Load()DimkAsInteger,aAsInteger,bAsIntegerDimcAsInteger,nAsIntegerShown=0Print三位数的水仙花数是:7Fork=100To999a=Int(k/100)b=Int((k-100*a)/10)c=kMod10Ifa*a*a+b*b*b+c*c*c=kThenPrintkn=n+1EndIfNextkPrint一共有&n&个水仙花数EndSubex0505PrivateSubForm_Load()ShowFork=1000To9999IfkMod78=0Thena=Int(k/1000)b=Int(k/100)-10*ac=Int(k/10)-100*a-10*bd=kMod10Ifa=bAndc=dThenPrintkEndIfEndIfNextkEndSubex0506PrivateSubCommand1_Click()DimsAsString,yAsStringDimxAsString,tAsStrings=Text1.Text:y=Fork=1ToLen(s)x=Mid(s,k,1)t=UCase(x)Ift=AAndt=ZTheny=y+xEndIfNextkText2.Text=yEndSubex05078PrivateSubCommand1_click()'显示按钮单击事件FontSize=12ClsFori=0ToList1.ListCount-1'逐项判断IfList1.Selected(i)Then'真时为选定PrintList1.List(i)EndIfNextiEndSubex0508PrivateSubForm_Load()ShowFora=1To9Forb=1To9Forc=1To9Ford=1To9x=a*1000+b*100+c*10+dy=b*1000+a*100+a*10+cz=d*100+d*10+aIfx-y=zThenPrintA=&a&,B=&b&,C=&c&,D=&dEndIfNextdNextcNextbNextaEndSubex0601PrivateSubCommand1_Click()Dima(10)AsInteger,minAsInteger,posAsIntegerRandomizeFori=1To10a(i)=Int(Rnd*90+10)Printa(i);NextiPrintmin=a(1)pos=1Fork=2To10Ifa(k)minThenmin=a(k)pos=k9EndIfNextkPrint最小数:;min,位置:;posEndSubex0602PrivateSubForm_Load()DimaAsVariant,bAsVariantDimc(8)AsIntegera=Array(3,4,2,1,5,7,8,11,13)b=Array(10,6,12,9,13,8,8,1,16)Fork=0To8c(k)=a(k)+b(k)NextkShowFork=0To8Printc(k)NextkEndSubex0603PrivateSubForm_Load()Dimd()AsIntegerDimkAsInteger,tAsInteger,mAsIntegerDimhAsInteger,nAsIntegern=Val(InputBox(请输入数组个数n:))ReDimd(n)ShowPrint处理前数据:RandomizeFork=1Tond(k)=Int((101*Rnd-50))Printd(k);NextkPrintm=Int(n/2)Fork=1Tomh=n-k+1t=d(h):d(h)=d(k):d(k)=tNextkPrint处理的结果:Fork=1TonPrintd(k);Nextk10EndSubex060

1 / 19
下载文档,编辑使用

©2015-2020 m.777doc.com 三七文档.

备案号:鲁ICP备2024069028号-1 客服联系 QQ:2149211541

×
保存成功