这个VB代码哪裏错了

来源:百度知道 编辑:UC知道 时间:2024/06/06 20:51:20
为什麼显示的是19个false
Private Sub Command1_Click()
Dim x As Integer, y As Integer, c As Integer
c = 0
For x = 0 To 240
For y = 0 To 100
If 5 * x + 13 * y = 1200 Then
List1.AddItem Str(x) + " " = Str(y)
c = c + 1
End If
Next y
Next x
Text1.Text = Str(c)

End Sub

Private Sub Command1_Click()
Dim x As Integer, y As Integer
static c As Integer
c = 0
For x = 0 To 240
For y = 0 To 100
If 5 * x + 13 * y = 1200 Then
List1.AddItem Str(x) + " " = Str(y)
c = c + 1
End If
Next y
Next x
Text1.Text = Str(c)

End Sub

List1.AddItem Str(x) + " " = Str(y) ‘这一句绝对错了,因为不知道你到底想干什么,所以只能先给你指出错误:List1.AddItem是行为;Str(x) + " " = Str(y)是关系语句,两者凑一起错!!
怎么改正需要你说出要求在百度hi我吧。

Str(x) + " " = Str(y)是一个表达式,一直到最后Str(x) + " "都不等于Str(y),表达式的整个值一直都是“FALSE”,所以添加的项目当然还是false啦(共循环了19次)。
你是不是想在列表框添加Str(x) + " "+Str(y)的值?如果是的话应该在If 5 * x + 13 * y = 1200 Then 下面插入:
s = Str(x) + " " + Str(y)
List1.AddItem s
并且去掉List1.AddItem Str(x) + " " = Str(y)这行代码。
运行结果是:
6 90
19 85
32 80
45 75
58 70
71 65
84 60
97 55
110 50
1