VB帮我看一下代码VB

来源:百度知道 编辑:UC知道 时间:2024/05/05 10:52:34
以下代码
当运行的时候
在星座那:无论输入的是什么月份,他输出的都是射手座.

怎么回事?

Dim a, b, c As Integer
Dim f, d As Date
Dim nianling As Single

Private Sub cmdcount_Click()
a = txtyear1.Text
b = txtmonth1.Text
c = txtday1.Text
d = Date
f = CDate(a & "-" & b & "-" & c)
lblnianling.Caption = CInt((d - f) / 356)

If txtmonth1.Text = "1" Then
ElseIf txtday1.Text >= "19" Then
lblxingzuo.Caption = "摩蝎座"
Else
lblxingzuo.Caption = "水瓶座"
End If

If txtmonth1.Text = "2" Then
ElseIf txtday1.Text >= "18" Then
lblxingzuo.Caption = "水瓶座"
Else
lblxingzuo.Caption = "双鱼座"
End If

If txtmonth1.Text = "3" Then
ElseIf txtday1.Text >= "20" Then
lblxingzuo.Caption = "双鱼座"
Else
lblxingzuo.Caption =

需要使用IF嵌套语句

修改后的代码如下:
Dim a, b, c As Integer
Dim f, d As Date
Dim nianling As Single

Private Sub cmdcount_Click()
a = txtyear1.Text
b = txtmonth1.Text
c = txtday1.Text
d = Date
f = CDate(a & "-" & b & "-" & c)
lblnianling.Caption = CInt((d - f) / 356)

If txtmonth1.Text = "1" Then
If txtday1.Text >= "19" Then
lblxingzuo.Caption= "摩蝎座"
Else
lblxingzuo.Caption = "水瓶座"
End If
End If

If txtmonth1.Text = "2" Then
If txtday1.Text >= "18" Then
lblxingzuo.Caption = "水瓶座"
Else
lblxingzuo.Caption = "双鱼座"
End If
End If
If txtmonth1.Text = "3" Then
If txtday1.Text >= "20" Then
lblxingzuo.Caption = "双鱼座"
Else
lblxingzuo.Caption = "牡羊座"
End If