问题描述
我有8个列表框,我需要比较存储在它们中的值,我需要找到每个列表框中每行中的第一个非数字字符,然后在列表框之间进行比较是否有人有任何想法如何做到这一点? br />
欢呼
黑匣子
I have 8 list boxes and i need to compare values stored in them, i need to find the first non-numerical character in each line in each listbox and then compare between listboxes does anyone have any ides how to do this?
cheers
Black box
推荐答案
嗨
dim lstbLine(7)
''找到第一个非数字chr是列表框的行并记住
''假设列表框被放入数组
''lstb是列表框的计数器
''ndx是非数字线的计数器
对于lstb = 0到7
for ndx = 0 to ListBox(lstb).ListCount-1
if asc(left(ListBox(lstb).List(ndx),1))> 64然后
lstbLine(lstb)= ndx
退出
结束如果
next ndx
next lstb
''比较不同的列表框行
for lstb = 0 to 6
for lstb1 = lstb +1到7
如果lstbLine(lstb)= lstbLine(lstb1)那么
那么
msgbox" Listbox" &安培; lstb& "具有与列表框相同的值 &安培; lstb1
结束如果
next lstb1
next lstb
hi
dim lstbLine(7)
''find first non-numerical chr is line of listbox and remember
''assumed listboxes are put into an array
''lstb is counter for listboxes
''ndx is counter for non-numerical line
for lstb=0 to 7
for ndx=0 to ListBox(lstb).ListCount-1
if asc(left(ListBox(lstb).List(ndx),1)) > 64 then
lstbLine(lstb)=ndx
exit for
end if
next ndx
next lstb
''compare different listbox lines
for lstb=0 to 6
for lstb1=lstb+1 to 7
if lstbLine(lstb)=lstbLine(lstb1) then
msgbox "Listbox " & lstb & " has same value as Listbox " & lstb1
end if
next lstb1
next lstb
这实际上并不符合规范。请求是找到每行中的第一个非数字字符。我相信这段代码会找到以非numneric开头的第一行。您可能实际上需要使用第三个嵌套循环来遍历ListBox(lstb).List(ndx)中的每个字符,并使用您找到的字符执行某些操作,然后退出。
如果你感兴趣,上面代码中的Left()函数是不必要的; ASC()函数无论如何都只返回第一个字符的ASCII值。
This doesn''t actually match the spec. The request was to find the "first non-numeric character in each line". I believe this code will find the first line which starts with a non-numneric. You might actually need to use a third nested loop to run through each character in ListBox(lstb).List(ndx), and do something with the character you find, then Exit For.
Just in case you''re interested, the Left() function in the above code is unnecessary; the ASC() function will only return the ASCII value of the first character anyway.
这篇关于VBA列表框帮助的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!