本文來(lái)源于網(wǎng)頁(yè)設(shè)計(jì)愛(ài)好者web開(kāi)發(fā)社區(qū)http://www.html.org.cn收集整理,歡迎訪(fǎng)問(wèn)。提供
單item函數(shù):
cmddel_click
cmdadd_click
多item函數(shù):
cmddelall_click
cmdaddall_click
---------------------------------------------------------------------------------------------------------------------
'option explicit
'author:nyb
'time:2002-04-05
'傳入list1,list2,然后我們可以對(duì)list1,和list2中的item進(jìn)行處理.
'*all areas of code where modifications are necessary
'*to integrate this object with a project are documented
'with comments denoted by note:.
'*to locate these comments,search for ‘*note::.
'****************************************************************************************
public sub cmddelall_click(list1 as listbox, list2 as listbox) '<<
'*purpose: delete all list2.item
'*accept: list1 沒(méi)有用,list2處理對(duì)象
 for i = (list2.listcount - 1) to 0 step -1
 list2.removeitem i
 next i
end sub
public sub cmdadd2to1_click(list1 as listbox, list2 as listbox, list3 as listbox) '>>
'*purpose: all item of list1 and list2 are inputed to list3
'*accept: list1,list2
 for i = 0 to (list1.listcount - 1)
 list3.additem list1.list(i)
 next i
 for i = 0 to (list2.listcount - 1)
 list3.additem list2.list(i)
 next i
end sub
public sub cmdaddall_click(list1 as listbox, list2 as listbox, index as integer) '>>
'*purpose: add all item of list1 inputed to list2.if item had been there, it won't be inputed
'*accept: list1,list2
 if list2.listcount = 0 then
 for i = 0 to (list1.listcount - 1)
 list2.additem list1.list(i)
 next i
 else
 for i = 0 to (list1.listcount - 1)
 flag = checkselected(list1, list2, list1.list(i))
 if flag = "notbe" then list2.additem list1.list(i)
 next i
 end if
end sub
public sub cmddel_click(list1 as listbox, list2 as listbox) '<---
'*purpose: the selected items of list2 are cleared
'*accept: list1 沒(méi)有用,list2處理對(duì)象
 dim i as integer
 if list2.selcount > 0 then
 for i = (list2.listcount - 1) to 0 step -1
 if list2.selected(i) = true then list2.removeitem i
 next i
 end if
end sub
public sub cmdadd_click(list1 as listbox, list2 as listbox, index as integer) '--->
'*purpose: the selected items of list1 is inputed into list2
' list2為空,list2又可以多選,那么items selected in list1 are inputed to list2
' list2不為空,list2又可以多選,那么先檢查item是否在list2中,如果在,那么就不添入list2
' list2設(shè)為單選,那么list2只添加list1中的的第一選中項(xiàng)
'*accept: list1 選中的項(xiàng)目,list2為要加入的listbox
 dim i as integer
 dim flag as string
 
 if index > 0 then
 if list2.listcount >= 1 then
 if index = 2 then
 if list2.listcount >= 2 then
 if list1.multiselect = 0 then
 msgbox "只能選定兩期對(duì)比!", vbexclamation, "操作提示!"
 exit sub
 end if
 end if
 end if
 end if
 end if
 
 if list2.listcount = 0 and list2.multiselect = 2 then
 for i = 0 to (list1.listcount - 1)
  if list1.selected(i) = true then list2.additem list1.list(i)
 next i
 elseif list2.listcount > 0 and list2.multiselect = 2 then
 for i = 0 to (list1.listcount - 1)
 flag = checkselected(list1, list2, list1.list(i))
 if list1.selected(i) = true and flag = "notbe" then list2.additem list1.list(i)
 next i
 elseif list2.multiselect = 0 then
 call cmddelall_click(list1, list2)
 for i = 0 to (list1.listcount - 1)
 if list1.selected(i) = true then list2.additem list1.list(i)
 next i
 end if
 call clearselect(list1)
end sub
private function checkselected(list1 as listbox, list2 as listbox, cityitem as string) as string
'*purpose: '檢查item是否已經(jīng)被添加,已添加則checkselected = "be"
'*accept: list1 選中的項(xiàng)目,list2為要加入的listbox,cityitem為list1 中一個(gè)被選中的項(xiàng)目
'*feedback: checkselected , "be" 表示這個(gè)item在list2中存在
 for i = (list2.listcount - 1) to 0 step -1
 if cityitem = list2.list(i) then
 checkselected = "be"
 exit for
 else: checkselected = "notbe"
 end if
 next i
end function
private sub clearselect(list1)
'*purpose: clear list1's selected
'*accept: list1 ,the list box to clear selected
 for i = 0 to list1.listcount - 1
 if list1.selected(i) = true then
 list1.selected(i) = false
 end if
 next i
end sub