vb中的小问题

来源:百度知道 编辑:UC知道 时间:2024/06/04 10:06:02
怎么把listbox里的所有数字加起来,谢谢。
希望能有具体的语句,谢谢。

'适用于 Windows XP SP2/VB6 SP6
'list1 为listbox control
dim i as integer
dim lSum as double
for i = 0 to list1.listcount-1
if isnumeric(list1.list(i)) then ' 判断是不是数字
lSum = lSum + list1.list(i) '加和
end if
next i
msgbox lSum '输出

遍历,类型转换,相加,搞定.

Dim i, j, s As Integer
s = 0
i = ListBox1.Items.Count() - 1
For j = 0 To i
s = s + Val(ListBox1.Items.Item(j).Text)
Next
Label1.Text = Str(s)