获得VB listbox 选中项目(多项)的一个好方法
传统方法是遍历一遍
如果listbox 项目过多
明显速度不行
好方法是通过sendmessge发消息给listbox让他把选中项目直接传到参数数组中
You can use the SendMessage() API function instead.
As
you probably know, this function lets you send a message to one or more
windows. The declaration statement conforms to the following syntax:
Private Declare Function SendMessage Lib "user32" _
Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg _
As Long, ByVal wParam As Long, lParam As Any) As Long
Since
we want to gather the listbox: selected items, we'll send the
LB_GETSELITEMS constant in the wMsg argument, which you declare like so:
Private Const LB_GETSELITEMS = &H191
The LB_GETSELITEMS message fills an array with the index numbers of all the selected items.
Dim ItemIndexes() As Long, x As Integer, iNumItems As Integer
iNumItems = ThisBox.SelCount
If iNumItems Then
ReDim ItemIndexes(iNumItems - 1)
SendMessage ListBox1.hwnd, LB_GETSELITEMS, iNumItems, ItemIndexes(0)
End If
For x = 0 To iNumItems - 1
MsgBox ListBox1.List(ItemIndexes(x)) '弹出对话框
Next x
After
being passed to the SendMessage function, iNumItems holds the total
number of selected items, and the ItemIndexes array holds the selected
item index values. Notice, that you must pass a pointer to the
ItemIndexes array, and not the array itself. Thus, we passed
ItemIndexes(0) into the SendMessage function, not ItemIndexes().
相关文档:
IDE:Visual Web Developer 2008 Express Edition
数据库:Access 2007
到http://www.asp.net/ajax/downloads/下载AJAX Control Toolkit,将AjaxControlToolkit.dll拷贝到项目的bin目录下,在工具栏中引入。
WebService的代码:(aaa.asmx)
Public Function GetCompletionList(ByVal prefixText As String, ByVal coun ......
近日分析一VB做的报表,由于对VB只是了解,谈不上熟练,不过对其水晶报表倒有点认识,之前也做过三两个小的报表 ,加之对PB中的报表了解非常熟悉,当时信心蛮大的。
先是看了DataReport,用于绘制报表格式。再来看DataEnvironment,用于定义获取的数据列。将DataReport与DataEnviro ......
从网上搜集到的VB代码,用EXE方式实现了远程注入,不过在反病毒软件的保护下,有可能导致注入失败。转贴这个代码,仅供大家学习和参考。
一、窗口代码:
Option Explicit
Private Sub cmdLock_Click()
If LockKeyboard(True) Then
cmdLock.Enabled = False
cmdUnLock.Enabled = Tr ......
使用VB把Excel导入到Sql数据库中,其实有几种方法。
下面我介绍的这种方法,较为简单。
其实这种方法的话,是直接使用T-SQL操作的,因此,到了VB里面,直接eccute这个代码就OK了的。
-----------------------------------------------------下面是在T-sql中的语句
if object_id('NewTable') is not null/*判断表NewTabl ......
很久以前的一个代码了。。。。。那时还沉迷于研究WindowsXP登录密码的计算方法。。。。
先新建一个VB工程,画一个CommandButton,改名为cmdGetSYSKEY,画一个TextBox,改名为txtSYSKEY,然后粘贴下面的代码,运行即可,在WindowsXP SP2 Build 2600 + VB6.0 SP6下测试通过,获得的SYSKEY与Cain&Abel v4.9.6一致。。。。 ......