谁能帮我用VB编个小程序啊?
发布网友
发布时间:2024-09-28 21:12
我来回答
共4个回答
热心网友
时间:2024-10-13 15:28
Dim a%, b%, x%, y%
a = InputBox("请输入足的总数")
b = InputBox("请输入头的总数")
x = 2 * b - a / 2
y = a / 2 - b
Print "鸡有"; x; "只"
Print "兔有"; y; "只"
热心网友
时间:2024-10-13 15:29
Private Sub Command1_Click()
a = InputBox("请输入鸡与兔的总数")
b = InputBox("请输入鸡与兔脚的总数")
For i = 1 To a
If Val(i) * 2 + Val(a - i) * 4 = b Then
Print "兔" & a - i
Print "鸡" & i
Exit For
End If
Next
End Sub
热心网友
时间:2024-10-13 15:28
Private Sub Command1_Click()
On Error GoTo ERR_EXIT
Dim n1 As Long, n2 As Long, x As Long, y As Long
Dim t As Double
n1 = CLng(Text1.Text) '脚的总数
If n1 <= 0 Or n1 Mod 2 <> 0 Then GoTo ERR_EXIT
n2 = CLng(Text2.Text) '动物的数量
If n2 <= 0 Or n1 < 2 * n2 Then GoTo ERR_EXIT
t = (n1 - 2 * n2) / 2 '兔的数量
x = (n1 - 2 * n2) \ 2 '兔的数量
If t <> x Or x > n2 Or x < 0 Then GoTo ERR_EXIT
y = n2 - x '鸡的数量
Text3.Text = "有兔 " & x & " 只,鸡 " & y & " 只"
Exit Sub
ERR_EXIT:
MsgBox "1、脚的数量必须为偶数且不得少于动物数量的2倍" & vbCrLf & "2、输入的数量无解"
End Sub
'界面请拖入三个文本框,一个按钮即可
热心网友
时间:2024-10-13 15:24
Private Sub Command1_Click()
Form1.AutoRedraw = True
Cls
Dim numCh, numRa As Integer '定义 鸡的数目与兔的数目
Dim numFeet, numTotal As Integer '定义脚的总数与 总的只数
Dim bool1, ok As Boolean
numTotal = val(InputBox("请输入总只数:"))
numFeet = val(InputBox("请输入脚的总数:"))
'判断输入是否合理,
Do While (numFeet Mod 2 <> 0) Or (2 * numTotal > numFeet)
MsgBox ("脚的总数 或者 总的只数 输入不正确,请重新输入")
numTotal = val(InputBox("请输入总只数:"))
numFeet = val(InputBox("请输入脚的总数:"))
Loop
'进行计算
bool1 = False
ok = False
For numRa = 0 To numTotal
numCh = numTotal - numRa
bool1 = (numRa * 4 + numCh * 2 = numFeet)
If (bool1) Then
ok = True
Print "The number of Rabbits is", numRa
Print
Print "The number of Chickens is", numCh
Print
Exit For
End If
Next numRa
'判断是否完成
If (ok) Then
Print "求解完毕!"
Print
Else
Print "无法求解!"
End If
End Sub