【VB开源代码栏目提醒】:网学会员为广大网友收集整理了,VB程序设计教程(第3版)课后实验答案 - 编程语言,希望对大家有所帮助!
实验A A1 Private Sub Command1_Click Label3 Text1 End Sub A2 Private Sub Form_Load Timer1.Interval 0 End Sub Private Sub Command1_Click 自动 Timer1.Interval 200 End Sub Private Sub Command2_Click 手动 Timer1.Interval 0 Call MyMove End Sub Private Sub Timer1_Timer Call MyMove End Sub Sub MyMove Label1.Move Label1.Left - 50 If Label1.Left lt 0 Then Label1.Left Form1.Width End Sub A3 Private Sub Form_Click Text1 ValText1 1 End Sub Private Sub Form_Load Text1 0 End Sub A4 Private Sub Form_Click Caption quot单击窗体改变图片quot Picture LoadPictureApp.Path quotn_015.bmpquot Print quot欢迎使用VBquot End Sub Private Sub Form_DblClick Cls Caption quot双击窗体卸去图片quot Picture LoadPicturequotquot End Sub Private Sub Form_Load Caption quot装入窗体quot Picture LoadPictureApp.Path quotn_016.bmpquot Print quot装入图quot End Sub Private Sub Form_Resize 该事件的作用窗体始终与图一样大 Caption quot窗体大小不变quot Form1.Width 260 16 260是Tongji-2.bmp图的宽度象素单位 Form1.Height 260 16 200 260是图的高度象素单位200是窗体的标题栏高度 End Sub A5 Sub Command1_Click Text1.FontName quot隶书quot Text1.FontSize 25 End Sub Sub Command2_Click Text2.Text Text1.SelText Text2.FontName Text1.FontName Text2.FontSize Text1.FontSize End Sub 实验B B1 Private Sub Command1_Click Text2 Format5 / 9 ValText1 - 32 quot0.00quot End Sub Private Sub Command2_Click Text1 Format9 / 5 ValText2 32 quot0.00quot End Sub 或 Private Sub Command1_Click Dim f c 声明两个变量 f ValText1 c 5 / 9 f - 32 Text2 Formatc quot0.00quot 保留两位小数 End Sub Private Sub Command2_Click Dim ff cc 声明两个变量 cc ValText2 ff 9 / 5 cc 32 Text1 Formatff quot0.00quot 保留两位小数 End Sub B2 Private Sub Command1_Click Label2 FormatValText1 ValText1 3.14 quot0.00quot End Sub Private Sub Command2_Click Label3 FormatValText1 3.14 2 quot0.00quot End Sub Private Sub Text1_LostFocus If Not IsNumericText1.Text Then MsgBox quot输入有非数字字符请重新输入quot quot警告quot Text1.Text quotquot Text1.SetFocus End If End Sub 或 Private Sub Command1_Click Label2 FormatValText1 ValText1 3.14 quot0.00quot End Sub Private Sub Command2_Click Label3 FormatValText1 3.14 2 quot0.00quot End Sub Private Sub Text1_KeyPressKeyAscii As Integer If KeyAscii 13 Then If Not IsNumericText1.Text Then Text1.Text quotquot End If End If End Sub B3 Private Sub Command1_Click n IntLog2 / Log1.008 1 Label1 n amp quot年后人数超过26亿quot End Sub B4 Private Sub Command1_Click Dim x dx cd x Text1.Text dx UCasex cd Lenx Print quot大写字母为:quot dx Print quot字符串长度为:quot cd End Sub B5 Private Sub Command1_Click Text1 IntRnd 900 100 End Sub Private Sub Command2_Click Dim x x1 x2 x3 x ValText1 x1 x Mod 10 分离出的个位数 x2 x Mod 100 10 分离出的十位数 x3 x 100 分离出的百位数 Label1 x1 100 x2 10 x3 End Sub B6 Private Sub Form_Click Label1 LeftText1 11 Label2 MidText1 12 6 Label3 RightText1 5 End Sub B7 Private Sub Command1_Click Print For i 1 To 5 Print Tab15 - i 2 String2 i - 1 quot★quot Spc18 - 4 i - 1 String2 i - 1 quot★quot Next i End Sub Private Sub Command2_Click Cls End Sub 进一步要求 Private Sub Command1_Click Print For i 1 To 5 Print Tab15 - i 2 String2 i - 1 quot★quot String10 - 2 i - 1 quot☆quot String2 i - 1 quot★quot Next i End Sub Private Sub Command2_Click Cls End Sub B8 Private Sub Form_Click x ValInputBoxquot输入一正实数quot quot计算quot 0 pf Formatx x quot0.000quot pfg FormatSqrx quot0.000quot lf Formatx x x quot0.000quot lfg Formatx 1 / 3 quot0.000quot Print quot平方为:quot pf Space5 quot平方根为:quot pfg Space5 quot立方为:quot lf Space5 quot立方根为:quot lfg End Sub 实验C C1 Private Sub Form_Click Dim x y x ValInputBoxquot输入x的值quot If x lt 1000 Then y x ElseIf x lt