dim AllStr as stringFor lTemp = LBound(bPicBuf()) To UBound(bPicBuf()) - 1
sTempStr = Hex$(bPicBuf(lTemp))
allstr=AllStr + string$(2-len(sTempStr),"0")+sTempStr
Next
Text1.text=allstr
sTempStr = Hex$(bPicBuf(lTemp))
allstr=AllStr + string$(2-len(sTempStr),"0")+sTempStr
Next
Text1.text=allstr
dim AllStr as string
For lTemp = LBound(bPicBuf()) To UBound(bPicBuf()) - 1
sTempStr = Hex$(bPicBuf(lTemp))
allstr=AllStr + string$(2-len(sTempStr),"0")+sTempStr+" "
Next
Text1.text=allstr
Private Sub Command7_Click()
Dim bPicBuf() As Byte
Dim lPicLen As Long
Dim sFileName As String
Dim lTemp As Long
Dim sTempStr As String
Dim AllStr As String
Text1.Text = ""
sFileName = List1.List(List1.ListIndex)
lPicLen = FileLen(sFileName)
ReDim bPicBuf(0 To lPicLen-1)
Open sFileName For Binary Access Read As #1
Get #1, , bPicBuf()
Close #1
For lTemp=0 To lPicLen-1
sTempStr=Hex$(bPicBuf(lTemp))
AllStr=AllStr+String$(2-len(sTempStr),"0")+sTempStr+" "
Next
Text1.text=allstr
Beep
End Sub
你这就不对了
文件操作要比内存操作慢多了!
TO: zyl910(910:分儿,我来了!)
你这就不对了
文件操作要比内存操作慢多了
不是已经读取到内存了?!
我只不过
把ta的Text1.Text改成了AllStr,因为这比读取属性快。
For循环中我改掉了取数组大小的函数。
Private Sub Command7_Click()
Dim tFileName As String
Dim tBytes() As Byte ReDim tBytes(0) tFileName=List1.List(List1.ListIndex)
BytesGetByFile tFileName,tBytes()
Text1.Text=StringGetByBytes(tBytes())End SubFunction StringGetByBytes(pBytes() As Byte) As String Dim tOutStr As String
Dim tLoop As Long
Dim tLoopOn As Long
Dim tLoopEnd As Long
Dim tStartHEX_H As String * 1
Dim tStartHEX_L As String * 1
Dim tStartByte As Byte tLoopOn=LBound(pBytes):tLoopEnd=UBound(pBytes) For tLoop=tLoopOn To tLoopEnd
tStartByte=Bytes(tLoop)
tStartHEX_H=Hex(tStartByte \ 16)
tStartHEX_L=Hex(tStartByte Mod 16)
tOutStr = tOutStr & tStartHEX_H & tStartHEX_L
Next StringGetByBytes=tOutStrEnd FunctionFunction BytesGetByFile(ByVal pFileName As String,pBytes() As Byte)
Dim tFileNumber As Integer
Dim tFileLen As Long tFileNumber=FreeFile Open pFileName For Binary As #tFileNumber
tFileLen = Len(#tFileNumber)
ReDim pBytes(tFileLen)
Get #1,1,pBytes(tFileLen)
Close #tFileNumberEnd Function
Sorry,我未仔细看
Get #1,1,pBytes(tFileLen)
改为:
Get #tFileNumber,1,pBytes(tFileLen)
小仙妹得慢慢看看,好麻烦呀,不是我要的主要是速度,我好好试试
谢谢各位,没问题马上加分
BytesGetByFile函数是把文件读到Byte数组里,这个数组没有返回。
StringGetByBytes是根据你的要求把Byte数组变成你要的字符串返回。
你遇到的HEX值缺0问题我用的是取高低位来解决的,而不是IF语句。我把Byte值整除16得到高位、Mod 16得到低位。
把BytesGetByFile函数的:
Get #tFileNumber,1,pBytes(tFileLen)
改为:
Get #tFileNumber,1,pBytes()
910,你的程序比我的块多了!原来17s的图片变为1s.原来72s的还是1s!新程序16s的原来的程序执行了1000s还没有结束!
小仙妹你的程序我马上试
tFileLen = Len(#tFileNumber)
tFileLen = Len(pFileName)可以了
还有错误:
tStartByte = Bytes(tLoop)
bytes不是函数呀,系统不认识
另外:tFileLen=Len(#tFileNumber)这句我写错了!是tFileLen=LOF(#tFileNumber)VERSION 5.00
Begin VB.Form Form1
Caption = "Form1"
ClientHeight = 4575
ClientLeft = 60
ClientTop = 345
ClientWidth = 5505
LinkTopic = "Form1"
ScaleHeight = 4575
ScaleWidth = 5505
StartUpPosition = 3 '窗口缺省
Begin VB.VScrollBar VScroll1
Height = 2655
Left = 4680
Max = 100
TabIndex = 5
Top = 1560
Width = 255
End
Begin VB.CommandButton Command4
Caption = ">"
Height = 255
Left = 4680
TabIndex = 4
Top = 1200
Width = 735
End
Begin VB.CommandButton Command3
Caption = "<"
Height = 255
Left = 4680
TabIndex = 3
Top = 840
Width = 735
End
Begin VB.CommandButton Command2
Caption = ">>"
Height = 255
Left = 4680
TabIndex = 2
Top = 480
Width = 735
End
Begin VB.CommandButton Command1
Caption = "<<"
Height = 255
Left = 4680
TabIndex = 1
Top = 120
Width = 735
End
Begin VB.TextBox Text1
Height = 4095
Left = 120
MultiLine = -1 'True
TabIndex = 0
Text = "FormMain.frx":0000
Top = 120
Width = 4455
End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Public pubByteLineWidth As Integer '显示列宽
Public pubByteLineMax As Integer '显示行数
Public pubByteLineStart As Long '当前行
Public pubLineMax As Long '最大行数
Dim pubFileBytes() As Byte '文件数组
Dim pubCacheBytes() As Byte '显示区Cache数组Private Sub Command1_Click()
pubByteLineStart = pubByteLineStart - pubByteLineMax
ViewUpData
End SubPrivate Sub Command2_Click()
pubByteLineStart = pubByteLineStart + pubByteLineMax
ViewUpData
End SubPrivate Sub Command3_Click()
pubByteLineStart = pubByteLineStart - 1
ViewUpData
End SubPrivate Sub Command4_Click()
pubByteLineStart = pubByteLineStart + 1
ViewUpData
End SubPrivate Sub Form_Load()
pubByteLineWidth = 16
pubByteLineMax = 16
pubByteLineStart = 0
CacheBytesReSet pubCacheBytes()
BytesGetByFile "Setup.bmp", pubFileBytes()
CacheBytesGetByBytes pubCacheBytes(), pubFileBytes()
Text1.Text = StringGetByCache(pubCacheBytes())
pubLineMax = UBound(pubFileBytes) \ pubByteLineWidth + 1
'Text1.Text = UBound(pubFileBytes)
End SubFunction ViewUpData()
If pubByteLineStart > pubLineMax Then
pubByteLineStart = pubLineMax
ElseIf pubByteLineStart < 0 Then
pubByteLineStart = 0
End If
CacheBytesGetByBytes pubCacheBytes(), pubFileBytes()
Text1.Text = StringGetByCache(pubCacheBytes())
VScroll1.Value = pubByteLineStart * 100 \ pubLineMax
End FunctionFunction StringGetByCache(pCache() As Byte) As String
'将Cache里的数据转换成一页字符
Dim tOutStr As String
Dim tLoop As Long
Dim tLoopOn As Long
Dim tLoopEnd As Long
Dim tByteHEX_H As String * 1
Dim tByteHEX_L As String * 1
Dim tByteStart As Byte
tLoopOn = LBound(pCache)
tLoopEnd = UBound(pCache)
For tLoop = tLoopOn To tLoopEnd
tByteStart = pCache(tLoop)
tByteHEX_H = Hex(tByteStart \ 16)
tByteHEX_L = Hex(tByteStart Mod 16)
tOutStr = tOutStr & tByteHEX_H & tByteHEX_L & " "
If Not CBool((tLoop + 1) Mod pubByteLineWidth) Then tOutStr = tOutStr & Chr(13) & Chr(10)
Next
StringGetByCache = tOutStr
End FunctionFunction CacheBytesGetByBytes(pCache() As Byte, pBytes() As Byte)
'从数组中提取当前显示区域的数据到Cache
Dim tLoop As Long
Dim tLoopOn As Long
Dim tLoopEnd As Long
Dim tMisreg As Long
Dim tFileLen As Long
Dim tAddress As Long
tMisreg = AddressGetByLine(pubByteLineStart)
tLoopOn = LBound(pCache)
tLoopEnd = UBound(pCache)
tFileLen = UBound(pubFileBytes)
For tLoop = tLoopOn To tLoopEnd
tAddress = tLoop + tMisreg
If tAddress < tFileLen Then
pCache(tLoop) = pBytes(tAddress)
Else
pCache(tLoop) = 0
End If
Next
End FunctionFunction AddressGetByLine(pLine As Long) As Long
'行号转换成地址
Dim tOutLng As Long
tOutLng = pLine * pubByteLineWidth
AddressGetByLine = tOutLng
End FunctionFunction CacheBytesReSet(pCacheBytes() As Byte)
'重定义Cache数组
Dim tCacheSize As Long
tCacheSize = CacheSizeGet(pubByteLineWidth, pubByteLineMax) - 1
ReDim pCacheBytes(tCacheSize)
End FunctionFunction CacheSizeGet(pLineWidth As Integer, pLineMax As Integer) As Long
'根据显示列宽和行数获得Cache数组尺寸
Dim tOutLng As Long
tOutLng = pLineWidth * pLineMax
CacheSizeGet = tOutLng
End FunctionFunction BytesGetByFile(pFileName As String, pBytes() As Byte)
'从文件获得全部数据到数组里
Dim tFileNumber As Integer
Dim tFileLen As Long
tFileNumber = FreeFile
Open pFileName For Binary As #tFileNumber
tFileLen = LOF(tFileNumber)
ReDim pBytes(tFileLen)
Get #tFileNumber, 1, pBytes()
Close #tFileNumber
End Function
Dim tBytes() As Byte
Dim tFileName As StringtFileName=你指定的文件名BytesGetByFile tFileName,tBytes() '将tFileName指定的文件读到数组tBytes()里
tString=StringGetByBytes(tBytes()) '将数组tBytes()变成你要的字符串。'下面是函数(有函数结构说明):
Function StringGetByBytes(pBytes() As Byte) As String
'把包含文件全部数据的数组转换成字符串。
'定义段:定义用到的变量
Dim tOutStr As String
Dim tLoop As Long
Dim tLoopOn As Long
Dim tLoopEnd As Long
Dim tStartHEX_H As String * 1
Dim tStartHEX_L As String * 1
Dim tStartByte As Byte '初始化段:准备好后面的工作所用的一切数值。
tLoopOn = LBound(pBytes): tLoopEnd = UBound(pBytes) '工作段:开始计算
For tLoop = tLoopOn To tLoopEnd
tStartByte = pBytes(tLoop)
tStartHEX_H = Hex(tStartByte \ 16)
tStartHEX_L = Hex(tStartByte Mod 16)
tOutStr = tOutStr & tStartHEX_H & tStartHEX_L & " "
Next
'输出段:把结果输出
StringGetByBytes = tOutStr
End FunctionFunction BytesGetByFile(pFileName As String, pBytes() As Byte)
'从文件获得全部数据到数组里
Dim tFileNumber As Integer
Dim tFileLen As Long
tFileNumber = FreeFile
Open pFileName For Binary As #tFileNumber
tFileLen = LOF(tFileNumber)
ReDim pBytes(tFileLen)
Get #tFileNumber, 1, pBytes()
Close #tFileNumber
End Function
比如:tStartByte = pBytes(tLoop)
写成: tStartByte = Bytes(tLoop),我还以为Bytes是什么函数呢,查了半天没找到!