关于VB中的列表框的问题
一道VB小程序
有两个列表框list1、 list2 。list1中初始化有15个不同的字母,而list2中是空白的 还有一个按钮command1,选中list1中的任意多个项目 然后点击按钮command1,则在list2中显示list1中被选中的项目。当多次选中list1中的同个项目时候,比如list1中的a被选中了3次 那么在list2中就有3个a.
我想问:怎样编写代码实现当list1中的项目不管被选中多少次,在list2中相同的只出现一次,即在list2中不要出现重复的字母。怎样实现呢?
思路:在command1中,被选中的项目存入数组变量sDate,循环该数组变量,里边嵌套list2的项目做循环,如果有相同的就不再往list2插入
dim b as boolean
for i =0 to ubound(sDate)
for j =1 to list2.ListCount
if sDate(i)= list2.list(j) then b=true
next j
if b=false then
list2.AddItem =sDate(i)
else
b=false
end if
next i
VB code:
Private Sub Command1_Click()
Dim i As Integer, j As Integer
Dim b As Boolean
For i = 0 To List1.ListCount - 1
If List1.Selected(i) Then
b = True
For j = 0 To List2.ListCount - 1
If List1.List(i) = List2.List(j) Then
b = False
Exit For
End If
Next j
If b Then List2.AddItem (List1.List(i))
相关问答:
Printer.ScaleMode = 6
6表示毫米
Printer.PaperSize = vbPRPSA4
'初始坐标
x = 1
y = 4
'最大的线筐
Printer.DrawStyle = 0
Printer.Line (x, y)-(x + 132.5, y) ......
大家好,问个vb打印问题
printer.print "dsff"
.....
....
Printer.EndDoc
打印成功后我将执行
sqlstr = "update vc_yh set pr=' 已打印 ', ......
VB中callbacke function 如下:
Public Function EnumChildProc(ByVal hwnd As Long, ByVal lParam As Long) As Long
Dim slength As Long, WndTitle As String ' title bar text length an ......
请教一下:我用vb写了一个调用Illustrator的测试程序,代码很简单:Private Sub Command1_Click()
Dim app As New Illustrator.Application
Dim doc As Illustrator.Document
Dim thislayer As Illustrator.Layer ......
我在窗体正常运行的情况下 标题栏上可以动态显示数值
可是点击最小化按钮的后 ,在任务栏上的标题上就不变了?
怎么办
别折腾这些花架子,没意义
不会吧?
VB code:
Private Su ......