VB根据生日计算星座
已知生日,格式如下1994-2-56,1987-10-88,1547-7-7,后面的数字位数不确定,怎样根据日期算出星座,要全部代码
补充:我的那个日期是通过日历控件得到的,不是输入的,因为月份的数字位数不确定,所以不会弄
追问:报错说溢出,怎么回事啊
已知生日,格式如下1994-2-56,1987-10-88,1547-7-7,后面的数字位数不确定,怎样根据日期算出星座,要全部代码
补充:我的那个日期是通过日历控件得到的,不是输入的,因为月份的数字位数不确定,所以不会弄
追问:报错说溢出,怎么回事啊
答案:'建立一个command1控件,一个text1控件
Option Explicit
Function Constellation(ByVal m As Date) As String '返回星座
Dim Number As Long
Number = Month(m) * 100 + Day(m)
Select Case Number
Case 321 To 419
Constellation = "白羊"
Case 420 To 520
Constellation = "金牛"
Case 521 To 621
Constellation = "双子"
Case 622 To 722
Constellation = "巨蟹"
Case 723 To 822
Constellation = "狮子"
Case 823 To 922
Constellation = "易做图"
Case 923 To 1023
Constellation = "天秤"
Case 1024 To 1121
Constellation = "天蝎"
Case 1122 To 1221
Constellation = "射手"
Case 1222 To 1231
Constellation = "摩蝎"
Case 101 To 119
Constellation = "摩蝎"
Case 120 To 218
Constellation = "水瓶"
Case 219 To 320
Constellation = "双鱼"
Case Else
Constellation = "无此星座!"
End Select
End Function
Private Sub Command1_Click()
If IsDate(Trim(Text1)) = True Then
MsgBox Constellation(Trim(Text1))
Else
MsgBox "日期格式错误!"
End If
End Sub
Private Sub Form_Load()
Command1.Caption = "星座"
Text1 = "1547-7-7"
End Sub以白羊座为例:
private function getXZ(byval dtDate as date) as string
if month(dtdate)>=3 and month(date)<=4 and day(dtdate)>=21 and day(dtdate)<=20 then
getXZ ="白羊座"
exit function
end if
end if
上一个:帮忙做套VB题
下一个:ASP与VB。NET