重拾VB之三,二进制文件篇
重拾VB之三,二进制文件篇
PMP 关劲松
鬼使神差,09年12月入职的公司仍使用VB开发软件,虽然并非专职开发,但也不得不在事隔4年之后,重新使用VB。
读取、修改二进制文件仍是大部分编程语言的基本开发技能。可以提高处理文件效率,主要应用在通信、交换数据等方面。
'open filename$ for binary #filenumber'以二进制方式建立或者打开文件,然后再用
'Put #FileNumber, postion, inputdata '写入数据inputdata,
'Get #FileNumber, postion, outputdata '读出数据到outputvarible
#FileNumber, 打开的二进制文件流。
postion, 文件中的数据位置。
inputdata 输入数据缓冲。可以使用数组或字符串。
outputdata 输出数据缓冲。可以使用数组或字符串。
代码
Sub read()
Dim strFileName1, s As String
Dim aryContent(20) As Byte
strFileName1 = App.Path & "\test.hex"
Open strFileName1 For Binary As 1
Get #1, 120, aryContent() '从文件中120字节处取出长度20的数据到数组中。
msgbox(aryContent()) '以16进制的方式显示。
s = Space(20) '重定义字符串长度。
Get #1, 2514, s ' 从文件中120字节处取出长度20的数据到字符串中。
msgbox(s) '以字符的方式显示。
Close 1
End Sub
Sub write()
Dim strFileName1, s As String
Dim aryContent(20) As Byte
strFileName1 = App.Path & "\test.hex"
Open strFileName1 For Binary As 1
s = Space(20)
s = "teststtsestssts33333"
Put #1, 2486, s '在文件中2486字节处写入长度20的字符串数据。
Debug.Print s
aryContent(0) = &H4F '初始化数组
aryContent(1) = &H33
aryContent(2) = &HA1
aryContent(3) = &H42
aryContent(4) = &H8D
Put #1, 2514, aryContent() ''在文件中2514字节处写入长度20的十六进制数组数据。
Debug.Print aryContent()
Close 1
End Sub
相关文档:
传统方法是遍历一遍
如果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 ......
引言:
做一个控件, 用于 数据采样如示波器, 可以添加,删除曲线, 设置曲线的相关属性: 线型,颜色,等...
过程:
先创建 线 类, 在用户控件里实现 线 对象创建, 并声明一个 集合, 用于 存放建立的线对象.
问题 ......
一、 VB读写EXCEL表:
VB本身提自动化功能可以读写EXCEL表,其方法如下:
1、在工程中引用Microsoft Excel类型库:
从"工程"菜单中选择"引用"栏;选择Microsoft Excel 9.0 Object Library(EXCEL2000),然后选择"确定"。表示在工程中要引用EXCEL类型库。
2、在通用对象 ......
“自动点击按钮”小工具VB源码
Option Explicit
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
Private Const WM_LBUTTONDOWN = &H201
Private Const WM_LBUTTONUP = &H202
Pri ......
可以筛选数据,但不能是标准的SQL语句:
Me.DsUserManager1.Tables(0).Select("id > 5 and id <20")
---------------------------------------------------------------
1.筛选:
dataset.tables("tabname").select("id=1")'相当于SQL中WHERE后的条件内容
2.保存到哪?这倒是不知 ......