2023年VisualBasic程序設(shè)計(jì)基礎(chǔ)課后習(xí)題參考答案_第1頁
2023年VisualBasic程序設(shè)計(jì)基礎(chǔ)課后習(xí)題參考答案_第2頁
2023年VisualBasic程序設(shè)計(jì)基礎(chǔ)課后習(xí)題參考答案_第3頁
2023年VisualBasic程序設(shè)計(jì)基礎(chǔ)課后習(xí)題參考答案_第4頁
2023年VisualBasic程序設(shè)計(jì)基礎(chǔ)課后習(xí)題參考答案_第5頁
已閱讀5頁,還剩55頁未讀 繼續(xù)免費(fèi)閱讀

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)

文檔簡介

第1章VisualBasic6.0程序設(shè)計(jì)概述一、判斷題1.√2.√3.4.√5.×6.√7.×8.√9.√10.×11.√12.√13.×14.√15.×16.√17.√18.√19.√20.√二、選擇題1.C2.B3.D4.C5.B6.A7.D8.A9.B10.A11.C12.D三、填空題1.對(duì)象、事件2.屬性、方法、事件3.控件、屏幕(Screen)4.對(duì)象5.Left、Top6.屬性、<對(duì)象名>.<屬性名>=<表達(dá)式>7.網(wǎng)格8.F orm19.Load或Initialize或Resize或Activate(自動(dòng)執(zhí)行的先后順序也按此排列)10.Activate、Deactivate四、程序設(shè)計(jì)題程序1.界面設(shè)計(jì)參看圖10-1、10-2以及表10-1。表10-1實(shí)例2各控件的重要屬性設(shè)立控件屬性(屬性值)屬性(屬性值)標(biāo)簽控件1Name(Label1)Caption("我的第一個(gè)VB程序")標(biāo)簽控件2Name(Label2)Caption("請(qǐng)輸入你的姓名")FontUnderLine(True)FontItalic(True)命令按鈕1Name(Command1)Caption("擬定(&O)")命令按鈕2Name(Command2)Caption("結(jié)束(&X)")過程設(shè)計(jì)如下:PrivatesubForm_Click()Command2.Enabled=FalseEenSubPrivateSubCommand1_Click()Label2.Visible=FalseLabel1.Caption=Text1.Text+":歡迎使用"+Label1.CaptionText1.Visible=FalseCommand1.Enabled=False:Command2.Enabled=TrueEndSubPrivateSubCommand2_Click()EndEndSub程序2.界面設(shè)計(jì)略,過程設(shè)計(jì)如下:PrivateSubCommand1_Click()'字體變大Form1.FontSize=Form1.FontSize+3Form1.Cls:Print"歡迎使用VB"EndSubPrivateSubCommand2_Click()'字體變小Form1.FontSize=Form1.FontSize-3Form1.Cls:Print"歡迎使用VB"EndSubPrivateSubCommand3_Click()'字體加粗Form1.FontBold=TrueForm1.Cls:Print"歡迎使用VB"EndSubPrivateSubCommand4_Click()'字體不加粗Form1.FontBold=FalseForm1.Cls:Print"歡迎使用VB"EndSub運(yùn)營時(shí),不得連續(xù)、過多次單擊“字體變小”按鈕,由于當(dāng)FontSize屬性值小于0會(huì)產(chǎn)生適時(shí)錯(cuò)誤。程序3.界面設(shè)計(jì)略,過程設(shè)計(jì)如下(窗體Height值的計(jì)量涉及標(biāo)題、邊框,而ScaleHeight值僅與窗體有效繪圖區(qū)域的高度有關(guān)):PrivateSubForm_Load()Text1.Text="VisualBasic程序設(shè)計(jì)"EndSubPrivateSubForm_Resize()Text1.Top=0:Text1.Left=0Command1.Top=Form1.ScaleHeight-Command1.HeightCommand1.Left=Form1.ScaleWidth-Command1.WidthEndSub第2章程序設(shè)計(jì)基礎(chǔ)一、判斷題1.√2.×3.×4.×5.√6.×7.√8.√9.√10.×二、選擇題1.B2.D3.A4.C5.C6.B7.A8.D9.C10.A三、填空題1.String2.43."aaa"4.1455.66.37.188.False9.(xMod10)*10+x\1010.10+Int(Rnd*90)11.a(chǎn)*bModc12.Log(x)+Sin(3.141593/6)13.ConstPI=3.141592614.日期15.Int(x)+1四、程序設(shè)計(jì)題程序1.界面設(shè)計(jì)略,過程設(shè)計(jì)如下:方法一、用文本框控件輸入圓的半徑PrivateSubCommand1_Click()DimxAsSinglex=Text1.TextLabel1.Caption=x*x*3.141593EndSub方法二、用InputBox函數(shù)輸入圓的半徑PrivateSubCommand1_Click()DimxAsSingle'若規(guī)定計(jì)算結(jié)果具有15位有效位數(shù),聲明x為Double類型x=InputBox("r=","輸入圓的半徑")Label1.Caption=x*x*3.141593EndSub程序2.略。第3章結(jié)構(gòu)化程序設(shè)計(jì)與數(shù)組一、判斷題1.√2.×3.√4.×5.√6.×7.×8.√9.×10.√二、選擇題1.A2.D3.C4.C5.D6.B三、填空題1.Ifx>yThent=y:y=x:x=t2.IS3.Fori=0to9:B(i)=InputBox("B("&i&")="):Nexti4.Dim5.String6.8四、程序閱讀題(寫出下列程序的運(yùn)營結(jié)果)程序1.05程序2.20程序3.2471116程序4.1491625程序5.程序6.五、程序填空題1.(1)q*i (2)s+p*i/q (3)Nexti2.(1)r=0 (2)mModn3.(1)i+j-1 (2)7-i (3)Print4.(1)10+Int(Rnd*90)(2)i+1To30(3)a(i)=a(j)(4)a(i)Mod2=1六、程序設(shè)計(jì)題程序1.界面設(shè)計(jì)略,過程設(shè)計(jì)如下:PrivateSubForm_Click()DimxAsInteger,yAsInteger,zAsIntegerDimmaxAsInteger,middAsInteger,minAsIntegerx=InputBox("請(qǐng)輸入x的值:")y=InputBox("請(qǐng)輸入y的值:")z=InputBox("請(qǐng)輸入z的值:")Ifx>yThenmax=xElsemax=yIfz>maxThenmax=zIfx<yThenmin=xElsemin=yIfz<minThenmin=zmidd=x+y+z-max-minPrintmax;midd;minEndSub程序2.界面設(shè)計(jì)略,過程設(shè)計(jì)如下:PrivateSubForm_Click()DimxAsSingle,yAsSinglex=InputBox("請(qǐng)輸入x的值:")Ifx>3Theny=x+3ElseIfx>=1Theny=x*xElseIfx>0Theny=Sqr(x)Elsey=0EndIfPrintyEndSub程序3.界面設(shè)計(jì)略,過程設(shè)計(jì)如下:PrivateSubForm_Click()DimiAsInteger,jAsIntegerFori=1To9Forj=1To9PrintTab((j-1)*4);i*j;NextjPrintNextiEndSub程序4.界面設(shè)計(jì)略,過程設(shè)計(jì)如下:PrivateSubForm_Click()DimxAsSingle,sAsSingle,tAsSingleDimiAsInteger,nAsIntegerx=InputBox("請(qǐng)輸入x的值:")n=InputBox("請(qǐng)輸入n的值:")t=x/2:s=tFori=3Tont=t*x/is=s+tNextiPrintsEndSub程序5.界面設(shè)計(jì)略,過程設(shè)計(jì)如下:PrivateSubForm_Click()DimeAsSingle,tAsSingle,iAsIntegere=2:t=1:i=1Whilet>=0.0001i=i+1:t=t/i:e=e+tWendPrinteEndSub程序6.界面設(shè)計(jì)略,過程設(shè)計(jì)如下:OptionBase1PrivateSubForm_Click()DimnAsInteger,a(9,9)AsInteger,iAsInteger,jAsIntegerOnErrorGoTok'下列代碼中若出現(xiàn)錯(cuò)誤,轉(zhuǎn)到標(biāo)號(hào)為K的語句執(zhí)行。n=InputBox("請(qǐng)輸入n,0<n<10")Fori=1Ton:a(i,1)=1:a(i,i)=1:NextiFori=3TonForj=2Toi-1a(i,j)=a(i-1,j-1)+a(i-1,j)Nextj,iFori=1TonPrintTab(30-2*i);Forj=1ToiPrintSpace(4-Len(Trim(Str(a(i,j)))));Trim(Str(a(i,j)));NextjPrintNextiExitSubk:MsgBox"輸入n值小于1或大于10,數(shù)組下標(biāo)超界。"EndSub第4章函數(shù)與過程一、判斷題1.×2.√3.×4.×5.√6.×7.×8.√二、填空題1.按地址傳送2.b()AsLong3.64.按值傳遞5.按地址傳遞6.PublicxAsSingle7.StaticxAsInteger8.Form2.y三、程序閱讀題(寫出下列程序的運(yùn)營結(jié)果)程序1.s=2程序2.1程序3.112112122223s=511s=9121133114641四、程序填空題1.(1)ByeVal (2)kModi (3)k=k\i (4)Callpp(i)2.(1)a()AaDouble (2)n-1 (3)a(j)<a(k)3.(1)a()AsDouble,nAsInteger (2)t=t*x (3)f=s五、程序設(shè)計(jì)題程序1.界面設(shè)計(jì)略,過程設(shè)計(jì)如下:PrivateFunctionfsum(x()AsDouble,nAsInteger)AsDoubleDimiAsIntegerFori=1Tonfsum=fsum+x(i)Nextifsum=fsum/nEndFunction程序2.界面設(shè)計(jì)略,過程設(shè)計(jì)如下:PrivateSubff(a()AsSingle,nAsInteger)DimiAsInteger,xAsSingleFori=1Ton\2x=a(n-i+1):a(n-i+1)=a(i):a(i)=xNextiEndSub程序3.界面設(shè)計(jì)略,過程設(shè)計(jì)如下:PrivateSubfind(x()AsSingle,mAsbyte,nAsByte,_xmaxAsSingle,kiAsByte,kjAsByte)xmax=x(1,1):ki=1:kj=1Fori=1TomForj=1TonNextj,iEndSub第5章常用控件一、判斷題1.×2.×3.×4.√5.×6.√7.×8.√9.√10.√11.×12.×13.√14.√15.×16.×17.×18.√19.√20.×21.√22.×23.√24.×25.√二、選擇題1.C2.D3.B4.B5.B6.C7.B8.B9.B10.A11.D12.C13.B14.B15.A16.D17.B18.B19.B20.A三、填空題1.上、下、左、左2.緹、無關(guān)3.&、<Alt>+<Y>4.Enabled5.MaxLength6.Text1.SetFocus7.MultiLine8.Visible9.Alignment10.AutoSize11.ForeColor12.0或113.True14.115.AddItem16.117.List1.Clear18.文本框、列表框19.下拉式組合框、簡樸組合框、下拉式列表框20.Scroll21.Value22.Change23.定期器不起作用24.Timer25.65535四、程序閱讀題程序1.116程序2.8程序3.23451程序4.小,你好!程序5.您好34512小李,你好!歡迎使用VisualBasic!程序6.李子程序7. y=6程序8. n=1蘋果 y=14 n=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=True1To2*i–1(2)Command2.Enabled=True(3)Command2.Enabled=False3.(1)Text2.Enabled=False(2)p=2(3)Printi(4)Val(Text1.Text)<2或Val(Text1.Text)<=1(5)KeyAscii=13(1)List1.ListCount(2)List1.RemoveItemI(3)i=i+1(1)Timer1.Enabled=True(2)x\3600(3)(xMod3600)\60或(x-3600*h)\60(4)x=x+16.(1)Label1.Left(2)Label1.Left=-Label1.Width六、程序設(shè)計(jì)題程序1.界面設(shè)計(jì)略,過程設(shè)計(jì)如下:PrivateSubCommand1_Click()IfCommand1.Caption="顯示"ThenPrint"歡迎使用VisualBasic!":Command1.Caption="清除"ElseForm1.Cls:Command1.Caption="顯示"EndIfEndSubPrivateSubCommand2_Click()EndEndSubPrivateSubForm_Load()Form1.Cls:Command1.Caption="顯示":Command2.Caption="退出"EndSub程序2.界面設(shè)計(jì)略,過程設(shè)計(jì)如下:PrivateSubForm_Load()Text1.MaxLength=1:Text1.Text=""EndSubPrivateSubText1_KeyPress(KeyAsciiAsInteger)Label1.Caption=CStr(KeyAscii)EndSub程序3.界面設(shè)計(jì)略,過程設(shè)計(jì)如下:ConstpwdAsString="123456"'預(yù)設(shè)密碼為123456PrivateSubCommand1_Click()Cls:Print"歡迎進(jìn)入!"EndSubPrivateSubForm_Load()Command1.Caption="進(jìn)入":Command1.Enabled=FalsewText1.Text="":Text1.PasswordChar="*"EndSubPrivateSubText1_KeyPress(KeyAsciiAsInteger)IfKeyAscii=13ThenIfText1.Text=pwdThenm=MsgBox("口令對(duì)的,歡迎進(jìn)入!"):Command1.Enabled=TrueElsem=MsgBox("口令錯(cuò)誤,請(qǐng)重新輸入!"):Text1.Text=""EndIfEndIfEndSub程序4.界面設(shè)計(jì)略,過程設(shè)計(jì)如下:DimnumAsInteger,mAsInteger,recAsIntegerPrivateSubForm_Load()Command1.Caption="出題":Command1.Enabled=TrueText1.Text="":Text1.Enabled=False:rec=0EndSubPrivateSubCommand1_Click()Randomize:num=Int(Rnd*100)+1:Text1.Enabled=TrueLabel1.Caption="":Command1.Enabled=FalseEndSubPrivateSubCommand2_Click()EndEndSubPrivateSubText1_KeyPress(KeyAsciiAsInteger)IfKeyAscii=13Thenm=Val(Text1.Text):rec=rec+1:Text1.SelStart=0Text1.SelLength=Len(Text1.Text):Text1.SetFocusIfrec>10ThenLabel1.Caption="差!重新開始":CallForm_LoadElseIfm>numThenLabel1.Caption=Str(m)&"大了!"ElseIfm<numThenLabel1.Caption=Str(m)&"小了!"ElseIfrec<5ThenLabel1.Caption="好!猜對(duì)了。"ElseLabel1.Caption="還行!猜對(duì)了。"EndIfCallForm_LoadEndIfEndIfEndIfEndSub程序5.界面設(shè)計(jì)如圖10-3所示,過程設(shè)計(jì)如下:PrivateSubForm_Load()Command1(0).Enabled=False:Command1(1).Enabled=FalseCommand1(2).Enabled=False:Label1.Caption=""EndSubPrivateSubCommand1_Click(IndexAsInteger)SelectCaseIndexCase0Clipboard.Clear:Clipboard.SetTextText1.SelTextText1.SelText="":Label1.Caption="請(qǐng)選擇要粘貼的位置!"Command1(0).Enabled=False:Command1(1).Enabled=FalseCommand1(2).Enabled=TrueCase1Clipboard.Clear:Clipboard.SetTextText1.SelTextLabel1.Caption="請(qǐng)選擇要粘貼的位置!":Command1(0).Enabled=FalseCommand1(1).Enabled=False:Command1(2).Enabled=TrueCaseElseText1.SelText=Clipboard.GetText():Form_LoadLabel1.Caption="粘貼完畢!"EndSelectEndSubPrivateSubText1_MouseUp(ButtonAsInteger,ShiftAsInteger,_XAsSingle,YAsSingle)DimnAsIntegern=Text1.SelLengthIfn>0ThenLabel1.Caption="選擇了"&n&"個(gè)字,請(qǐng)選擇下一步操作!"Command1(0).Enabled=True:Command1(1).Enabled=TrueElseLabel1.Caption=""EndIfEndSub程序6.界面設(shè)計(jì)如圖10-4所示,過程設(shè)計(jì)如下:PrivateSubForm_Load()Label1.Caption="當(dāng)前日期:":Text1.Text=DateOption1(0).Caption="顯示日期":Option1(1).Caption="顯示時(shí)間"Option1(0).Value=True:Command1.Caption="退出"EndSubPrivateSubOption1_Click(IndexAsInteger)SelectCaseIndexCase0Label1.Caption="當(dāng)前日期:":Text1.Text=DateCase1Label1.Caption="當(dāng)前時(shí)間:":Text1.Text=TimeEndSelectEndSubPrivateSubCommand1_Click()EndEndSub程序7.過程設(shè)計(jì)如下:PrivateSubForm_Load()Label1.Caption="當(dāng)前日期:":Text1.Text=DateOption1(0).Caption="顯示日期":Option1(1).Caption="顯示時(shí)間"Option1(0).Value=True:Command1.Caption="退出"Combo1.AddItem"年-月-日":Combo1.AddItem"月-日-年"Combo1.AddItem"日-月-年":Combo1.Text="年-月-日"EndSubPrivateSubCombo1_Click()DimnAsStringSelectCaseCombo1.ListIndexCase0:n="yyyy-mm-dd"Case1:n="mm-dd-yyyy"Case2:n="dd-mm-yyyy"EndSelectText1.Text=Format(Date,n)EndSubPrivateSubOption1_Click(IndexAsInteger)SelectCaseIndexCase0:Label1.Caption="當(dāng)前日期:":Text1.Text=DateCase1:Label1.Caption="當(dāng)前時(shí)間:":Text1.Text=TimeEndSelectEndSubPrivateSubCommand1_Click()EndEndSub程序8.界面設(shè)計(jì)如圖10-5所示,過程設(shè)計(jì)如下:PrivateSubForm_Load()List1.AddItem"happy":List1.AddItem"apple"List1.AddItem"student":List1.AddItem"computer"EndSubPrivateSubCommand1_Click()List1.AddItemText1.Text:Text1.SetFocusText1.SelStart=0:Text1.SelLength=Len(Text1.Text)EndSubPrivateSubCommand3_Click()List1.ClearEndSubPrivateSubCommand4_Click()EndEndSubPrivateSubCommand2_Click()IfList1.ListIndex<>-1ThenList1.RemoveItemList1.ListIndexEndSub9.界面設(shè)計(jì)如圖10-6所示,過程設(shè)計(jì)如下:PrivateSubForm_Load()Option1(0).Caption="八進(jìn)制":Option1(1).Caption="十六進(jìn)制"Option1(2).Caption="二進(jìn)制"EndSubPrivateFunctiontran(kAsLong,nAsInteger)AsStringDimxAsInteger,yAsString*1,k1AsLongtran="":k1=Abs(k)DoWhilek1>0x=k1ModnIfx>=10Theny=Chr(Asc("A")+x-10)Elsey=CStr(x)tran=y+trank1=k1\nLoopIfk<0Thentran="-"+tranEndFunctionPrivateSubOption1_Click(IndexAsInteger)DimkAsLong,nAsIntegerk=Val(Text1.Text)SelectCaseIndexCase0Label2.Caption="八進(jìn)制":n=8Case1Label2.Caption="十六進(jìn)制":n=16Case2Label2.Caption="二進(jìn)制":n=2EndSelectText2.Text=tran(k,n)EndSub10.界面設(shè)計(jì)如圖10-7所示,過程設(shè)計(jì)如下:PrivateSubForm_Load()Label1.Left=Width/2-Label1.Width/2Label1.AutoSize=TrueHScroll1.Min=1:HScroll1.Max=1000HScroll1.SmallChange=10:HScroll1.LargeChange=100HScroll1.Value=500:Timer1.Interval=500EndSubPrivateSubHScroll1_Change()Timer1.Interval=HScroll1.ValueEndSubPrivateSubHScroll1_Scroll()CallHScroll1_ChangeEndSubPrivateSubTimer1_Timer()Label1.FontSize=Label1.FontSize+2Label1.Left=Width/2-Label1.Width/2IfLabel1.FontSize>=72ThenTimer1.Enabled=FalseEndSub第6章圖形控件和圖形方法一、判斷題1.√2.×3.√4.×5.√6.×7.×8.×9.√10.√二、選擇題1.C2.B3.C4.A5.A6.C7.A8.C9.C10.B11.A12.B13.B14.C15.C三、填空題1.Circle(ScaleLeft+ScaleWidth/2,ScaleTop+ScaleHeight/2),8002.LoadPicture3.AutoSize、Stretch、False、False4.選中、屬性5.形狀、矩形6.Picture1.Picture=LodePicture("C:\Windows\Cloud.bmp")7.圖片框、其他控件8.緹、SclaeMode9.顏色10.顏色、圓弧起點(diǎn)處轉(zhuǎn)角、圓弧終點(diǎn)處轉(zhuǎn)角、橢圓縱軸與橫軸長度之比四、程序閱讀題程序1.轉(zhuǎn)動(dòng)一條紅色直線,其軌跡形成一個(gè)圓程序2.在窗體上隨機(jī)的位置、用隨機(jī)的顏色、半徑繪制1000個(gè)空心的圓。程序3.在圖片框內(nèi)繪制多個(gè)黃色邊框矩形,填充樣式在“實(shí)心”、“透明”間交替變換。五、程序填空題1.(1)Combo1.ListIndex(2)Shape1.BorderStyle(3)Combo2.AddItemStr(i)2.(1)Callpic(2)False (3)n=n+1(4)LoadPicture("c:\windows\1.bmp") (4)LoadPicture(fn)六、程序設(shè)計(jì)題程序1.界面設(shè)計(jì)略,過程設(shè)計(jì)如下:PrivateSubForm_Load()Picture1.ScaleMode=3EndSubPrivateSubCommand1_Click()Dimx1AsSingle,y1AsSingle,x2AsSingle,y2AsSinglex1=InputBox("x1="):y1=InputBox("y1=")x2=InputBox("x2="):y2=InputBox("y2=")Picture1.Line(x1,y1)-(x2,y2),,BEndSub程序2.界面設(shè)計(jì)略,過程設(shè)計(jì)如下:PrivateSubForm_click()DimrAsSingle,xoAsSingle,yoAsSingleIfForm1.ScaleHeight<Form1.ScaleWidthThenr=Form1.ScaleHeight/3Elser=Form1.ScaleWidth/3EndIfxo=Form1.ScaleLeft+Form1.ScaleWidth/2yo=Form1.ScaleTop+Form1.ScaleHeight/2Form1.FillStyle=0:Form1.FillColor=vbBlueForm1.DrawWidth=2:Form1.ScaleMode=6Form1.Circle(xo,yo),r,vbYellowEndSub程序3.界面設(shè)計(jì)略,過程設(shè)計(jì)如下:PrivateSubForm_Load()DimiAsIntegerFori=1To7:List1.AddItemi:NextiForm1.ScaleMode=1EndSubPrivateSubList1_Click()Form1.Cls:Form1.ScaleMode=List1.TextForm1.Circle(Form1.ScaleLeft+Form1.ScaleWidth/2,_Form1.ScaleTop+Form1.ScaleHeight/2),50EndSub第7章對(duì)話框與菜單程序設(shè)計(jì)一、判斷題1.√2.√3.√4.×5.×6.×7.√8.√9.√10.√二、選擇題1.D2.A3.C4.C5.B6.D7.A8.B9.D10.B三、填空題1.窗體控制菜單、下拉式菜單、快捷菜單2.ShowFont3.打開文獻(xiàn)、另存為、顏色、字體、打印對(duì)話框4.工程、部件5.CommonDialog1.Action=3、CommonDialog1.ShowColor6.提醒信息、對(duì)話框類型、對(duì)話框標(biāo)題7.Click8.工具9.代碼窗口、Click10.相同、正四、程序閱讀題程序1.顯示提醒信息為“5”、標(biāo)題為“na的輸出結(jié)果”、有一個(gè)“擬定”按鈕的消息框。程序2.顯示提醒信息為“您選擇了第1項(xiàng)”、標(biāo)題為“第一項(xiàng)”、有一個(gè)“擬定”按鈕的消息框。五、程序填空題1.(1)Int(Rnd*100) (2)Str(i) (3)ExitFor2.(1)False (2)Date (3)CommonDialog1.Color(4)m1六、程序設(shè)計(jì)題程序1.界面設(shè)計(jì)略,過程設(shè)計(jì)如下:PrivateSubCommand1_Click()CommonDialog1.ShowOpenList1.AddItemCommonDialog1.FileNameEndSub程序2.界面設(shè)計(jì)略,過程設(shè)計(jì)如下:PrivateSubCommand1_Click()CommonDialog1.ShowSaveList1.AddItemCommonDialog1.FileNameEndSub程序3.界面設(shè)計(jì)如圖10-9、表10-2所示,過程設(shè)計(jì)如下:PrivateSubSqr_Click()Shape1.Shape=1EndSubPrivateSubRec_Click()Shape1.Shape=0EndSubPrivateSubOval_Click()Shape1.Shape=2EndSubPrivateSubCircle_Click()Shape1.Shape=3EndSubPrivateSubRrec_Click()Shape1.Shape=4EndSubPrivateSubRSqr_Click()Shape1.Shape=5EndSubPrivateSubShp_Click()Shape1.FillStyle=2EndSubPrivateSubShzh_Click()Shape1.FillStyle=3EndSubPrivateSubXiex_Click()Shape1.FillStyle=4EndSubPrivateSubShPJ_Click()Shape1.FillStyle=6EndSubPrivateSubXJ_Click()Shape1.FillStyle=7EndSubPrivateSubFillColor_Click()CommonDialog1.ShowColorShape1.FillColor=CommonDialog1.ColorEndSubPrivateSubExit_Click()EndEndSub第8章文件一、判斷題1.×2.√3.×4.√5.√6.×7.√8.×9.√10.√11.×12.×13.√14.×15.×二、選擇題1.A2.C3.B4.B5.A6.C7.C8.B9.C10.B11.D12.B13.B三、填空題1.ChDir2.FileLen3.Change4.EOF5.LineInput四、程序閱讀題程序1. y=1a=1程序2.NO.13程序3. y=3a=2NO.24窗體:362516941 y=6a=3NO.37文獻(xiàn):149162536 y=10a=4 NO.411程序4.程序5.1程序6.1窗體上顯示內(nèi)容:202212文獻(xiàn)中內(nèi)容:4681012333123444455555五、程序填空題1.(1)DimnAsInteger(2)"C:\windows\calc.exe" (3)Output(4)End2.(1)ForOutputAs#2(2)0 (3)"temp.dat"As"c:\a1.dat"3.(1)Open"e:\dataout.txt"ForOutputAs#1(2)t1Modt2=0(3)IfflagThen (4)Printcoun六、程序設(shè)計(jì)題程序1.界面設(shè)計(jì)如圖10-10所示,過程設(shè)計(jì)如下:DimfnAsStringPrivateSubDrive1_Change()Dir1.Path=Drive1.DriveEndSubPrivateSubDir1_Change()File1.Path=Dir1.PathEndSubPrivateSubFile1_Click()IfRight(File1.Path,1)="\"Thenfn=File1.Path+File1.FileNameElsefn=File1.Path+"\"+File1.FileNameEndIfEndSubPrivateSubCommand1_Click()DimyesnoAsByteyesno=MsgBox("確認(rèn)要?jiǎng)h除嗎?",vbYesNo,"刪除文獻(xiàn)")Ifyesno=vbYesThenKillfnFile1.RefreshEndSub程序2.建立4個(gè)文本框控件依次輸入姓名、出生年月、外語、計(jì)算機(jī)成績,按“確認(rèn)”按鈕追加該記錄到磁盤文獻(xiàn)d:\student.dat。過程設(shè)計(jì)如下:PrivateSubCommand1_Click()DimbAsDate,mAsByte,eAsByteOpen"d:\student.dat"ForAppendAs#1b=Text2.Text:m=Text3.Text:e=Text4.TextWrite#1,Text1.Text,b,m,eText1.Text="":Text2.Text="":Text3.Text="":Text4.Text=""Close#1EndSub程序3.界面設(shè)計(jì)如圖10-11所示,過程設(shè)計(jì)如下:PrivateSubForm_Load()DimssAsStringOpen"e:\student.txt"ForAppendAs#1 '如文獻(xiàn)不存在則先建立該文獻(xiàn)Close#1Open"d:\student.dat"ForInputAs#1'將文獻(xiàn)中所有記錄在列表框中顯示W(wǎng)hileNotEOF(1)LineInput#1,ss:List1.AddItemssWendClose#1'在選中表項(xiàng)之前“刪除”、“修改”按鈕不可用Command2.Enabled=False:Command3.Enabled=FalseEndSubPrivateSubList1_Click()'選中表項(xiàng)后可“刪除”或“修改”,不可“追加”。Command1.Enabled=False:Command2.Enabled=TrueCommand3.Enabled=True:Text1.Text=List1.TextEndSubPrivateSubCommand1_Click()'追加記錄IfTrim(Text1.Text)<>""ThenList1.AddItemText1.TextText1.Text=""EndSubPrivateSubCommand2_Click()'修改記錄List1.AddItemText1.Text,List1.ListIndexList1.RemoveItemList1.ListIndexCommand1.Enabled=True:Command2.Enabled=FalseEndSubPrivateSubCommand3_Click()'刪除記錄List1.RemoveItemList1.ListIndex'刪除后,不可“刪除”、“修改”Command1.Enabled=True:Command2.Enabled=FalseCommand3.Enabled=False:Text1.Text=""EndSubPrivateSubCommand4_Click()'保存文獻(xiàn),將列表框中所有表項(xiàng)輸出到文獻(xiàn)DimiAsIntegerOpen"d:\student.dat"ForOutputAs#1Fori=0ToList1.ListCount-1:Print#1,List1.List(i):NextiClose#1EndSubPrivateSubCommand5_Click()'退出之前先保存文獻(xiàn)CallCommand4_Click:EndEndSub第9章數(shù)據(jù)庫與數(shù)據(jù)訪問技術(shù)一、判斷題1.√2.√3.×4.√5.×6.×7.√8.√9.×10.×11.√12.√13.√14.√15.√16.×17.×18.×19.√20.√21.√22.×二、選擇題1.A2.D3.C4.B5.C6.A7.C8.D9.D10.C11.A12.D13.A14.B15.B16.C三、程序設(shè)計(jì)題程序1.(1)數(shù)據(jù)訪問控件以及數(shù)據(jù)綁定控件的相關(guān)屬性設(shè)立如下Text1:DataSource("Data1")、DataField("學(xué)號(hào)")Text2:DataSource("Data1")、DataField("姓名")Check1:DataSource("Data1")、DataField("性別")Text3:DataSource("Data1")、DataField("出生日期)Text4:DataSource("Data1")、DataField("獎(jiǎng)學(xué)金")Text5:DataSource("Data1")、DataField("簡歷")OLE1:DataSource("Data1")、DataField("照片")Adodc1:ConnectionString("Provider=Microsoft.Jet.OLEDB.4.0;_DataSource=E:\GYH\VB\學(xué)籍1b.mdb;PersistSecurityInfo=False")CommandType("1-adCmdText")、RecordSource("select*from成績")DataGrid1:DataSource("Adodc1")(2)重要事件過程代碼OptionExplicitPrivateSubForm_Load()Caption="學(xué)籍信息編輯瀏覽"Label1.Caption="學(xué)號(hào):":Label2.Caption="姓名:"Label3.Caption="出生年月:":Label4.Caption="獎(jiǎng)學(xué)金:"Label5.Caption="簡歷:":Label6.Caption="照片:"Check1.Caption="性別(選中表達(dá)男,否則為女)"Label7.Caption="成績信息查詢顯示":Adodc1.Visible=FalseEndSubPrivateSubData1_Reposition()Label7.Caption=Trim(Data1.Recordset("姓名"))&"成績信息查詢顯示"Adodc1.RefreshEndSub程序2.(1)數(shù)據(jù)訪問控件以及數(shù)據(jù)綁定控件的相關(guān)屬性設(shè)立如下:Adodc1:ConnectionString("Provider=Microsoft.Jet.OLEDB.4.0;_DataSource=E:\GYH\VB\學(xué)籍1b.mdb;PersistSecurityInfo=False"CommandType("1-adCmdText")、RecordSource("select*from學(xué)生)DataGrid1:DataSource("Adodc1")(2)重要事件過程代碼OptionExplicitPrivateSubForm_Load()DimiAsIntegerCaption="學(xué)籍信息查詢?yōu)g覽":Adodc1.Visible=FalseLabel1.Caption="選擇查詢方式:":Combo1.Text="所有都顯示"Label2.Caption="所有表文獻(xiàn)數(shù)據(jù)瀏覽表格:":Label3.Visible=FalseText1.Visible=False:Text1.Text=""Fori=0To2Combo1.AddItemMid("所有都顯示按學(xué)號(hào)查詢按姓名查詢",5*i+1,5)NextiEndSubPrivateSubCombo1_Click()SelectCaseCombo1.ListIndexCase0Text1.Visible=False:Label3.Visible=FalseAdodc1.RecordSource="select*from學(xué)生"Label2.Caption="所有表文獻(xiàn)數(shù)據(jù)瀏覽表格:":Adodc1.RefreshCase1Label3.Caption="輸入查詢條件(學(xué)號(hào)):":Text1.Visible=TrueLabel3.Visible=True:Text1.SetFocusCase2Label3.Caption="輸入查詢條件(姓名):":Text1.Visible=TrueLabel3.Visible=True:Text1.SetFocusEndSelectEndSubPrivateSubText1_KeyDown(KeyCodeAsInteger,ShiftAsInteger)IfKeyCode=vbKeyReturnThenIfCombo1.ListIndex=1ThenAdodc1.Recordset.MoveFirstAdodc1.Recordset.Find"學(xué)號(hào)='"&Text1.Text&"'"IfAdodc1.Recordset.EOFThenAdodc1.RecordSource="select*from學(xué)生"Label2.Caption="所有表文獻(xiàn)數(shù)據(jù)瀏覽表格:"Adodc1.Refresh:MsgBox"查無此人!"ElseAdodc1.RecordSource="select*from學(xué)生"&"where_學(xué)號(hào)='"&Text1.Text&"'"Label2.Caption="學(xué)生"+Text1.Text+"的數(shù)據(jù)瀏覽表格:"EndIfElseAdodc1.Recordset.MoveFirstAdodc1.Recordset.Find"姓名='"&Text1.Text&"'"IfAdodc1.Recordset.EOFThenAdodc1.RecordSource="select*from學(xué)生"Label2.Caption="所有表文獻(xiàn)數(shù)據(jù)瀏覽表格:"Adodc1.Refresh:MsgBox"查無此人!"ElseAdodc1.RecordSource="select*from學(xué)生"&_"where姓名='"&Text1.Text&"'"EndIfEndIfAdodc1.RefreshEndIfEndSub程序3.(1)數(shù)據(jù)訪問控件以及數(shù)據(jù)綁定控件的相關(guān)屬性設(shè)立如下:Adodc1(xs):ConnectionString("Provider=Microsoft.Jet.OLEDB.4.0;_DataSource=E:\GYH\VB\學(xué)籍1b.mdb;PersistSecurityInfo=False")CommandType("2-adCmdTable")、RecordSource("學(xué)生")Adodc2(kc):ConnectionString("Provider=Microsoft.Jet.OLEDB.4.0;_DataSource=E:\GYH\VB\學(xué)籍1b.mdb;PersistSecurityInfo=False")CommandType("2-adCmdTable")、RecordSource("課程")Adodc3(cjcx):ConnectionString("Provider=Microsoft.Jet.OLEDB.4.0;_DataSource=E:\GYH\VB\學(xué)籍1b.mdb;PersistSecurityInfo=False")CommandType("1-adCmdText")RecordSource("select成績.學(xué)號(hào),學(xué)生.姓名,成績.課程號(hào),課程.課程名,_成績.成績from學(xué)生,課程,成績where成績.課程號(hào)=課程.課程號(hào)_and成績.學(xué)號(hào)=學(xué)生.學(xué)號(hào)"DataGrid1:DataSource("cjcx")DataList1:RowSource("xs")、ListField

("姓名")、BoundColumn("學(xué)號(hào)")(2)重要事件過程代碼OptionExplicitDimpAsBytePrivateSubForm_Load()DimiAsIntegerFori=0To4Label1(i).Caption=Mid("優(yōu)秀良好中檔及格差等",2*i+1,2)Text1(i).Text="":Text1(i).BackColor=RGB(205,205,192)Text1(i).Locked=TrueNexti&"成績.成績from學(xué)生,課程,成績"&_"where成績.課程號(hào)=課程.課程號(hào)and成績.學(xué)號(hào)=學(xué)生.學(xué)號(hào)"cjcx.Refresh:Label2.Caption="成績信息列表"Label3.Caption="選擇學(xué)生姓名:":Label4.Caption="選擇課程名:"xs.Visible=False:kc.Visible=False:cjcx.Visible=FalseCaption="學(xué)籍信息查詢":p=0EndSubPrivateSubDataList1_Click()p=0:CallcjdctjEndSubPrivateSubDataList2_Click()p=1:CallcjdctjEndSubPrivateSubcjdctj()Dimcjdcjs(5)AsInteger,dcaseAsByte,iAsByteIfp=0Thencjcx.RecordSource="select成績.學(xué)號(hào),學(xué)生.姓名,成績.課程號(hào),"_&"課程.課程名,成績.成績from學(xué)生,課程,成績"_&"where成績.學(xué)號(hào)='"&DataList1.BoundText&"'"_&"and(成績.課程號(hào)=課程.課程號(hào)and"_&"成績.學(xué)號(hào)=學(xué)生.學(xué)號(hào))orderby成績.課程號(hào)"Frame1.Caption="單位:門"Label2.Caption=Trim(DataList1.Text)&"成績信息列表"Elsecjcx.RecordSource="select成績.學(xué)號(hào),學(xué)生.姓名,成績.課程號(hào),"_&"課程.課程名,成績.成績from學(xué)生,課程,成績"_&"where成績.課程號(hào)='"&DataList2.BoundText&"'"_&"and(成績.課程號(hào)=課程.課程號(hào)and"_&"成績.學(xué)號(hào)=學(xué)生.學(xué)號(hào))orderby成績.學(xué)號(hào)"Frame1.Caption="單位:人"Label2.Caption=Trim(DataList2.Text)&"成績信息列表"EndIfcjcx.RefreshIfNotcjcx.Recordset.EOFThencjcx.Recordset.MoveFirstWhileNotcjcx.Recordset.EOFIfcjcx.Recordset("成績")<60Thendcase=0Elsdcase=(cjcx.Recordset("成績")\10)–5 EndIfSelectCasedcaseCase4,5:cjdcjs(0)=cjdcjs(0)+1Case3:cjdcjs(1)=cjdcjs(1)+1Case2:cjdcjs(2)=cjdcjs(2)+1Case1:cjdcjs(3)=cjdcjs(3)+1Case0:cjdcjs(4)=cjdcjs(4)+1EndSelectcjcx.Recordset.MoveNextWendFori=0To4:Text1(i).Text=cjdcjs(i):NextiEndSub程序4.(1)數(shù)據(jù)訪問控件以及數(shù)據(jù)綁定控件的相關(guān)屬性設(shè)立如下:Adodc1:ConnectionString("Provider=Microsoft.Jet.OLEDB.4.0;_DataSource=E:\GYH\VB\學(xué)籍1b.mdb;PersistSecurityInfo=False")CommandType("2-adCmdTable")、RecordSource("學(xué)生")LockType("4-adBatchOptimistic)Adodc2:ConnectionString("Provider=Microsoft.Jet.OLEDB.4.0;_DataSource=E:\GYH\VB\學(xué)籍1b.mdb;PersistSecurityInfo=False")CommandType("2-adCmdTable")、RecordSource("課程")LockType("4-adBatchOptimistic")Adodc3:ConnectionString("Provider=Microsoft.Jet.OLEDB.4.0;_DataSource=E:\GYH\VB\學(xué)籍1b.mdb;PersistSecurityInfo=False")CommandType("2-adCmdTable")、RecordSource("成績")LockType("4-adBatchOptimistic")Text1:用于顯示編輯"學(xué)號(hào)",但是本字段不設(shè)立數(shù)據(jù)綁定屬性,輸入或修改后的"學(xué)號(hào)"數(shù)據(jù)通過代碼方式寫入數(shù)據(jù)源中。Text2:DataSource("Adodc1")、DataField("姓名")Check1:DataSource("Adodc1")、DataField("性別")Text3:DataSource("Adodc1")、DataField("出生日期")Text4:DataSource("Adodc1")、DataField("獎(jiǎng)學(xué)金")Text5:用于顯示編輯"課程號(hào)",但是本字段不設(shè)立數(shù)據(jù)綁定屬性,輸入或修改后的"課程號(hào)"數(shù)據(jù)通過代碼方式寫入數(shù)據(jù)源中。Text6:DataSource("Adodc2")、DataField("課程名")Text7:DataSource("Adodc2")、DataField("學(xué)時(shí)數(shù)")Text8:DataSource("Adodc2")、DataField("學(xué)分?jǐn)?shù)")Text9:DataSource("Adodc2")、DataField("開課學(xué)期")Text10:DataSource("Adodc2")、DataField("考試考察標(biāo)志")Text11:用于顯示編輯成績表中的"學(xué)號(hào)",但是本字段不設(shè)立數(shù)據(jù)綁定屬性,輸入或修改后的"學(xué)號(hào)"數(shù)據(jù)通過代碼方式寫入數(shù)據(jù)源中。Text12:用于顯示編輯成績表中的"課程號(hào)",但是本字段不設(shè)立數(shù)據(jù)綁定屬性,輸入或修改后的"課程號(hào)"數(shù)據(jù)通過代碼方式寫入數(shù)據(jù)源中。Text12:DataSource("Adodc3")、DataField("成績")(2)重要事件過程代碼OptionExplicitDimvltAsBoolean,

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。

評(píng)論

0/150

提交評(píng)論