您好,欢迎访问三七文档
-1-《VB.NET程序设计》实验参考答案实验1-3Dimn%=0PrivateSubForm1_Click(……)HandlesMe.Clickn=n+1TextBox1.Text=nEndSub实验1-4PrivateSubForm1_Load(……)HandlesMyBase.LoadMe.Text=装入窗体Me.BackgroundImage=Image.FromFile(tongji.bmp)'当前目录为Bin的DebugMe.Cursor=NewCursor(key04.ico)Me.Icon=NewIcon(MISC34.ICO)EndSubPrivateSubForm1_Click(……)HandlesMyBase.ClickMe.Text=单击窗体'Me.Size=NewSize(264+10,256+30)'图片大小为×Me.BackgroundImage=Image.FromFile(tongji-2.bmp)EndSubPrivateSubForm1_DoubleClick(……)HandlesMyBase.DoubleClick-2-Me.Text=双击窗体Me.MaximizeBox=FalseMe.MinimizeBox=FalseMe.BackgroundImage=NothingMe.Cursor=Cursors.DefaultEndSubPrivateSubForm1_Resize(……)HandlesMe.ResizeMe.Size=NewSize(264+10,256+30)Me.FormBorderStyle=Windows.Forms.FormBorderStyle.Fixed3DEndSub实验1-5PrivateSubButton1_Click(……)HandlesButton1.ClickTextBox1.Font=NewFont(隶书,20)EndSubPrivateSubButton2_Click(……)HandlesButton2.ClickTextBox2.Text=TextBox1.SelectedTextTextBox2.Font=TextBox1.FontEndSub实验1-6Dimw%,h%-3-PrivateSubForm1_Load(……)HandlesMe.Loadw=PictureBox1.Widthh=PictureBox1.HeightEndSubPrivateSubButton2_Click(……)HandlesButton2.ClickPictureBox1.Width=wPictureBox1.Height=hEndSubPrivateSubButton1_Click(……)HandlesButton1.Click,Button1.ClickPictureBox1.Width=PictureBox1.Width/2PictureBox1.Height=PictureBox1.Height/2EndSub实验2-1PrivateSubButton1_Click(……)HandlesButton1.ClickTextBox1.Text=Int(Rnd()*10+0)TextBox2.Text=Int(Rnd()*90+10)TextBox3.Text=Int(Rnd()*(999-100+1)+100)EndSubPrivateSubButton2_Click(……)HandlesButton2.ClickDimavg!avg=(Val(TextBox1.Text)+Val(TextBox2.Text)+-4-Val(TextBox3.Text))/3Label2.Text=三个数的平均值为:&Format(avg,0.00)EndSubPrivateSubButton3_Click(……)HandlesButton3.ClickEndEndSub实验2-4PrivateSubButton1_Click(……)HandlesButton1.ClickDimn%n=Val(InputBox(输入个数))Label2.Text=Button1.Text&函数的结果TextBox2.Text=StrDup(n,TextBox1.Text)EndSubPrivateSubButton2_Click(……)HandlesButton2.ClickLabel2.Text=Button2.Text&函数的结果TextBox2.Text=UCase(TextBox1.Text)EndSubPrivateSubButton3_Click(……)HandlesButton3.ClickLabel2.Text=Button3.Text&函数的结果TextBox2.Text=LCase(TextBox1.Text)EndSubPrivateSubButton4_Click(……)HandlesButton4.Click-5-Dimn,mAsIntegern=Val(InputBox(输入n))m=Val(InputBox(输入m))TextBox2.Text=Mid(TextBox1.Text,n,m)Label2.Text=Button4.Text&函数的结果EndSubPrivateSubButton5_Click(……)HandlesButton5.ClickLabel2.Text=Button5.Text&函数的结果TextBox2.Text=Len(TextBox1.Text)EndSubPrivateSubButton6_Click(……)HandlesButton6.ClickDims1$s1=Val(InputBox(输入s1))TextBox2.Text=InStr(TextBox1.Text,s1)Label2.Text=Button6.Text&函数的结果EndSubPrivateSubButton7_Click(……)HandlesButton7.ClickDims1$,news$s1=InputBox(输入s1)news=InputBox(输入news)TextBox2.Text=Replace(TextBox1.Text,s1,news)Label2.Text=Button7.Text&函数的结果-6-EndSubPrivateSubButton8_Click(……)HandlesButton8.ClickLabel2.Text=Button8.Text&函数的结果TextBox2.Text=Trim(TextBox1.Text)EndSub实验2-5PrivateSubButton1_Click(……)HandlesButton1.ClickLabel2.Text=Button1.Text&函数的结果TextBox2.Text=Val(TextBox1.Text)EndSubPrivateSubButton2_Click(……)HandlesButton2.ClickLabel2.Text=Button2.Text&函数的结果TextBox2.Text=Str(TextBox1.Text)EndSubPrivateSubButton3_Click(……)HandlesButton3.ClickLabel2.Text=Button3.Text&函数的结果TextBox2.Text=Chr(TextBox1.Text)EndSubPrivateSubButton4_Click(……)HandlesButton4.ClickTextBox2.Text=Asc(TextBox1.Text)Label2.Text=Button4.Text&函数的结果EndSub-7-实验3-2PrivateSubButton1_Click(……)HandlesButton1.ClickDimx!,y!IfNotIsNumeric(TextBox1.Text)ThenMsgBox(error)TextBox1.Text=TextBox1.Focus()Elsex=TextBox1.TextIfx10Theny=30ElseIfx50Theny=x*2.5Elsey=x*2EndIfIfy150Theny=150EndIfTextBox2.Text=yEndSub实验3-7PrivateSubButton1_Click(……)HandlesButton1.Click-8-Dima#,b#,c#,dt!,s1$,s2$a=Val(TextBox1.Text)b=Val(TextBox2.Text)c=Val(TextBox3.Text)dt=b^2-4*a*cIfdt0Then'实根dt=Math.Sqrt(dt)Label3.Text=Format((-b+dt)/2/a,0.00)Label5.Text=Format((-b-dt)/2/a,0.00)ElseIfdt=0Then'重根dt=Math.Sqrt(dt)Label3.Text=Format(-b/2/a,0.00)Label5.Text=Format(-b/2/a,0.00)Elsedt=Math.Sqrt(-dt)'复根s1=Format(-b/2/a,0.00)s2=Format(dt/2/a,0.00)Label3.Text=s1&+&s2&iLabel5.Text=s1&-&s2&iEndIfEndSub实验3-89'If语句Dimn%,s$n=InputBox(输入一个数字~7)Ifn=1Thens=星期一ElseIfn=2Thens=星期二ElseIfn=3Thens=星期三ElseIfn=4Thens=星期四ElseIfn=5Thens=星期五ElseIfn=6Thens=星期六Elses=星期日EndIfMsgBox(s)'Select语句:SelectCasenCase1s=星期一Case2s=星期二Case3s=星期三Case4s=星期四Case5s=星期五Case6s=星期六Case7s=星期日EndSelect'Choose(函数)s=Choose(n,星期一,星期二,星期三,星期四,星期五,-10-星期六,星期日)实验4-2PrivateSubButton1_Click(……)HandlesButton1.ClickDimi%,c$Label1.Text=Fori=1To9c=StrDup(18-2*i,Chr(i+64))label1.text&=Space(i)&c&vbCrLfNextiEndSub实验4-5PrivateSubButton1_Click(……)HandlesButton1.Click‘三重循环Dimi%,j%,k%,t%Label1.text=Fori=1To9Forj=0To9Fork=0To9t=i*100+j*10+kIft=i^3+j^3+k^3ThenLabel1.text&=t&vbCrLfEndIf-11-NextkNextjNextiEndSub或者:PrivateSubButton2_Click(……)HandlesButton2.Click‘单重循环Dimi%,j%,k%,t%Label2.Text=Fort=100To999i=t\100j=(tMod100)\10k=tMod10Ift=i^3+j^3+k^3ThenLabel2.Text&=t&vbCrLfEndIfNexttEndSub实验4-7PrivateSubForm1_Load(……)HandlesMe.LoadHScrollBar1.Maximum=1HScrollBar1.Maximum=9-12-HScrollBar2.Minimum=5HScrollBar1.Maximum=10EndSubPrivateSubHScrollBar1_Scroll1(……)HandlesHScrollBar1.ScrollLabel1.Text=a=&HSc
本文标题:VB实验参考答案
链接地址:https://www.777doc.com/doc-2854043 .html