五笔打字通主页
VB程序题:输入一个数字(1~7),分别通过Select语句和Choose函数两种方法用英文显示对应的星期一~星期日,效果如图所示:
解题:按要求建立1个文本框用于输入数据,再建立3个标签控件,其中标签2,3用于接收输出。相应的代码如下:
Dim n!
Private Sub Command1_Click() 'Select语句
Select Case Trim(Text1)
Case 1
Label2 = "Monday"
Case 2
Label2 = "Tuesday"
Case 3
Label2 = "Wednesday"
Case 4
Label2 = "Thursday"
Case 5
Label2 = "Friday"
Case 6
Label2 = "Saturday"
Case 7
Label2 = "Sunday"
Case Is > 7, Is < 1
MsgBox "数字为1~7,请重新输入!"
Text1 = ""
Text1.SetFocus
End Select
End Sub
Private Sub Command2_Click() 'Choose函数
If Val(Text1) >= 7 Or Val(Text1) <= 1 Then
MsgBox "数字为1~7,请重新输入!"
Text1 = ""
Text1.SetFocus
Else
Label3 = Choose(Text1, "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday")
End If
End Sub
程序运行效果图如下:
Visual Basic程序设计教程(第四版) (龚沛曾等编)课后实验源码
来源:济亨网
本文链接:http://wb86.com/post/139.html