使用VB6.0开发应用程序时常用到的一些东西汇总:
1.关于注册表的操作
'COM口和波特率
ComStyle = GetSetting("infrared", "settings", "com")
Bps = GetSetting("infrared", "settings", "Bps")
'如果是第一次使用程序,则令ComStyle=1
If ComStyle = 0 Then
ComStyle = 1
SaveSetting "infrared", "settings", "com", 1
End If
If Bps = 0 Then
Bps = 4800
SaveSetting "infrared", "settings", "Bps", 4800
End If
2.'通讯控件设置
With mscomm1
.CommPort = ComStyle
.PortOpen = False
.Settings = "4800,n,8,1"
.InputLen = 11 '用input指令每次读取11个字节
.InputMode = comInputModeBinary
.RThreshold = 11 '每收到11个字节就触发OnComm事件
.InBufferSize = 1024
End With
3.导出数据到EXCEL表格中
Dim xlApp As Object '定义Excel类
Dim xlBook As Object '定义Excel工作薄类
Dim xlSheet As Object '定义工作表类
Dim i, j As Integer
Set xlApp = CreateObject("Excel.Application") '创建Excel应用类
xlApp.Visible = True '设置为可见
Set xlBook = xlApp.workbooks.Add '打开工作薄
Set xlSheet = xlBook.worksheets(1) '打开工作表
xlSheet.Activate '激活工作表
xlSheet.cells(1, 1) = " 日期"
xlSheet.cells(1, 2) = " 时间"
xlSheet.cells(1, 3) = " " & strCF
For i = 1 To n
xlSheet.cells(i + 1, 1) = savenum(i)
xlSheet.cells(i + 1, 2) = savetime(i)
xlSheet.cells(i + 1, 3) = savedata(i)
Next i
4.
文章评论(0条评论)
登录后参与讨论