VB作业题。。。
实例”菜单中的“判断属相”怎么做啊?不胜感谢
实例”菜单中的“判断属相”怎么做啊?不胜感谢
答案:1.Dim a(1 To 12) As String Private Sub Command1_Click() n = Combo1.Text If n <= 0 Then MsgBox "请输入大于0的数!": Exit Sub If n < 12 Then n = n + 12 End If If n >= 12 Then r = n Mod 12 Select Case r Case 4: sx = "鼠" Case 5: sx = "牛" Case 6: sx = "虎" Case 7: sx = "兔" Case 8: sx = "龙" Case 9: sx = "蛇" Case 10: sx = "马" Case 11: sx = "羊" Case 0: sx = "猴" Case 1: sx = "鸡" Case 2: sx = "狗" Case 3: sx = "猪" End Select End If Label1.Caption = sx End Sub Private Sub Form_Load() Label1.Caption = "" Label1.FontSize = 30 Label1.ForeColor = vbBlue End Sub 2.给你写个函数 自己带进你的代码 private sub Commmand1_Click() label1.caption=shengxiao(val(combo1.text)) end sub Function ShengXiao(Birth As Integer) As String Dim I As Integer, P As Integer Const ShX As String = "鼠牛虎兔龙蛇马羊猴鸡狗猪" P = 3 If Birth < 2010 Then For I = 2009 To Birth Step -1 P = P - 1 If P = 0 Then P = 12 Next I ElseIf Birth > 2010 Then For I = 2011 To Birth P = P + 1 If P = 13 Then P = 1 Next I End If ShengXiao = Mid(ShX, P, 1) End Function 很久不接触了,看了一下教程,也不知道对不对,运行试试吧。无可奉告,都在酒里面呢。