窗体设计可以按照我的截图!控件就不说了!很简单!添加控件后直接把代码复制进去就行了!
代码如下:'判断数据是否是整数!
Public Function isInt(s As String) As Boolean
If CStr(CInt(Val(s))) = s Then
isInt = True
Else
isInt = False
End If
End Function
'根据头数和脚数求解兔子的数量的方程
Public Function Solv(head As Integer, foot As Integer) As Integer
Dim Rabit As Integer
Rabit = (foot - head * 2) / 2
Solv = Rabit
End Function
Private Sub Command1_Click()
Dim err As String, OK As String
Dim h_num As Integer, f_num As Integer
If isInt(Text1.Text) Then
h_num = CInt(Text1.Text)
Else
err = err + "头数不是正整数!"
End If
If isInt(Text2.Text) Then
f_num = CInt(Text2.Text)
Else
err = err + "脚数不是正整数!"
End If
If err = "" Then
OK = OK & "兔子数量为:" & CStr(Solv(h_num, f_num)) & vbCrLf
OK = OK & "鸡的数量为:" & CStr(h_num - Solv(h_num, f_num)) & vbCrLf
MsgBox OK, vbOKOnly, "结果显示"
Else
MsgBox err, vbOKOnly, "出错了"
End If
End Sub