VB实验参考答案(40页).doc
《VB实验参考答案(40页).doc》由会员分享,可在线阅读,更多相关《VB实验参考答案(40页).doc(42页珍藏版)》请在淘文阁 - 分享文档赚钱的网站上搜索。
1、-VB.NET程序设计实验参考答案实验1-3Dim n% = 0 Private Sub Form1_Click() Handles Me.Click n = n + 1 TextBox1.Text = nEnd Sub实验1-4Private Sub Form1_Load() Handles MyBase.Load Me.Text = 装入窗体 Me.BackgroundImage = Image.FromFile(tongji.bmp) 当前目录为Bin的Debug Me.Cursor = New Cursor(key04.ico) Me.Icon = New Icon(MISC34.IC
2、O) End Sub Private Sub Form1_Click() Handles MyBase.Click Me.Text = 单击窗体 Me.Size = New Size(264 + 10, 256 + 30) 图片大小为 Me.BackgroundImage = Image.FromFile(tongji-2.bmp) End Sub Private Sub Form1_DoubleClick() Handles MyBase.DoubleClick Me.Text = 双击窗体 Me.MaximizeBox = False Me.MinimizeBox = False Me.B
3、ackgroundImage = Nothing Me.Cursor = Cursors.Default End Sub Private Sub Form1_Resize() Handles Me.Resize Me.Size = New Size(264 + 10, 256 + 30) Me.FormBorderStyle = Windows.Forms.FormBorderStyle.Fixed3DEnd Sub实验1-5Private Sub Button1_Click() Handles Button1.Click TextBox1.Font = New Font(隶书, 20) En
4、d Sub Private Sub Button2_Click() Handles Button2.Click TextBox2.Text = TextBox1.SelectedText TextBox2.Font = TextBox1.FontEnd Sub实验1-6Dim w%, h% Private Sub Form1_Load() Handles Me.Load w = PictureBox1.Width h = PictureBox1.Height End Sub Private Sub Button2_Click() Handles Button2.Click PictureBox
5、1.Width = w PictureBox1.Height = h End Sub Private Sub Button1_Click() Handles Button1.Click, Button1.Click PictureBox1.Width = PictureBox1.Width / 2 PictureBox1.Height = PictureBox1.Height / 2End Sub实验2-1Private Sub Button1_Click() Handles Button1.Click TextBox1.Text = Int(Rnd() * 10 + 0) TextBox2.
6、Text = Int(Rnd() * 90 + 10) TextBox3.Text = Int(Rnd() * (999 - 100 + 1) + 100) End Sub Private Sub Button2_Click() Handles Button2.Click Dim avg! avg = (Val(TextBox1.Text) + Val(TextBox2.Text) + Val(TextBox3.Text) / 3 Label2.Text = 三个数的平均值为: & Format(avg, 0.00) End Sub Private Sub Button3_Click() Ha
7、ndles Button3.Click EndEnd Sub实验2-4Private Sub Button1_Click() Handles Button1.Click Dim n% n = Val(InputBox(输入个数) Label2.Text = Button1.Text & 函数的结果 TextBox2.Text = StrDup(n, TextBox1.Text) End Sub Private Sub Button2_Click() Handles Button2.Click Label2.Text = Button2.Text & 函数的结果 TextBox2.Text =
8、UCase(TextBox1.Text) End Sub Private Sub Button3_Click() Handles Button3.Click Label2.Text = Button3.Text & 函数的结果 TextBox2.Text = LCase(TextBox1.Text) End Sub Private Sub Button4_Click() Handles Button4.Click Dim n, m As Integer n = Val(InputBox(输入n) m = Val(InputBox(输入m) TextBox2.Text = Mid(TextBox
9、1.Text, n, m) Label2.Text = Button4.Text & 函数的结果 End Sub Private Sub Button5_Click() Handles Button5.Click Label2.Text = Button5.Text & 函数的结果 TextBox2.Text = Len(TextBox1.Text) End Sub Private Sub Button6_Click() Handles Button6.Click Dim s1$ s1 = Val(InputBox(输入s1) TextBox2.Text = InStr(TextBox1.Te
10、xt, s1) Label2.Text = Button6.Text & 函数的结果 End Sub Private Sub Button7_Click() Handles Button7.Click Dim s1$, news$ s1 = InputBox(输入s1) news = InputBox(输入news) TextBox2.Text = Replace(TextBox1.Text, s1, news) Label2.Text = Button7.Text & 函数的结果 End Sub Private Sub Button8_Click() Handles Button8.Clic
11、k Label2.Text = Button8.Text & 函数的结果 TextBox2.Text = Trim(TextBox1.Text) End Sub实验2-5Private Sub Button1_Click() Handles Button1.Click Label2.Text = Button1.Text & 函数的结果 TextBox2.Text = Val(TextBox1.Text) End Sub Private Sub Button2_Click() Handles Button2.Click Label2.Text = Button2.Text & 函数的结果 Te
12、xtBox2.Text = Str(TextBox1.Text) End Sub Private Sub Button3_Click() Handles Button3.Click Label2.Text = Button3.Text & 函数的结果 TextBox2.Text = Chr(TextBox1.Text) End Sub Private Sub Button4_Click() Handles Button4.Click TextBox2.Text = Asc(TextBox1.Text) Label2.Text = Button4.Text & 函数的结果 End Sub实验3-
13、2 Private Sub Button1_Click() Handles Button1.Click Dim x!, y!If Not IsNumeric(TextBox1.Text) Then MsgBox(error) TextBox1.Text = TextBox1.Focus() Else x = TextBox1.Text If x 10 Then y = 30 ElseIf x 150 Then y = 150 End If TextBox2.Text = y End Sub 实验3-7Private Sub Button1_Click() Handles Button1.Cli
14、ck Dim a#, b#, c#, dt!, s1$, s2$ a = Val(TextBox1.Text) b = Val(TextBox2.Text) c = Val(TextBox3.Text) dt = b 2 - 4 * a * c If dt 0 Then 实根 dt = Math.Sqrt(dt) Label3.Text = Format(-b + dt) / 2 / a, 0.00) Label5.Text = Format(-b - dt) / 2 / a, 0.00) ElseIf dt = 0 Then 重根 dt = Math.Sqrt(dt) Label3.Text
15、 = Format(-b / 2 / a, 0.00) Label5.Text = Format(-b / 2 / a, 0.00) Else dt = Math.Sqrt(-dt) 复根 s1 = Format(-b / 2 / a, 0.00) s2 = Format(dt / 2 / a, 0.00) Label3.Text = s1 & + & s2 & i Label5.Text = s1 & - & s2 & i End If End Sub实验3-8If 语句 Dim n%, s$ n = InputBox(输入一个数字7) If n = 1 Then s = 星期一 ElseI
16、f n = 2 Then s = 星期二 ElseIf n = 3 Then s = 星期三 ElseIf n = 4 Then s = 星期四 ElseIf n = 5 Then s = 星期五 ElseIf n = 6 Then s = 星期六 Else s = 星期日 End If MsgBox(s) Select语句: Select Case n Case 1 s = 星期一 Case 2 s = 星期二 Case 3 s = 星期三 Case 4 s = 星期四 Case 5 s = 星期五 Case 6 s = 星期六 Case 7 s = 星期日 End Select Choos
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- VB 实验 参考答案 40
限制150内