大家帮我看看问题出在哪?怎么每次运行都提示“类型错误”

2024年11月29日 10:40
有2个网友回答
网友(1):

将 If year = "" Then 改为

If year =0 Then
因为year的数据类型为Single而不是String

网友(2):

'给你改好了复制粘贴即可
Private Sub Command1_Click()
Dim year As Single, p As String
year = Val(Text1.Text)
If Text1.Text = "" Then'year是数值型,text1.text是字符串
MsgBox "请输入年号!", 0, "检查是否输入年号"
End If
If year Mod 400 = 0 Or (year Mod 4 = 0 And year Mod 100 <> 0) Then
p = "该年为闰年"
Else
p = "该年不是闰年"
End If
Label2 = p
End Sub
Private Sub Text1_GotFocus()
Text1.SelStart = 0
Text1.SelLength = Len(Text1.Text)
End Sub
Private Sub Text1_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then
Command1.SetFocus
End If
End Sub