⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 数据转换.bas

📁 文件传送
💻 BAS
字号:
Attribute VB_Name = "数据转换"
Option Explicit

Public sendcp As Boolean


'内存复制的API函数
Public Declare Sub CopyMemory Lib "KERNEL32" Alias "RtlMoveMemory" (Destination As Any, Source As Any, ByVal Length As Long)



'用来使字串转换成数组的函数
Function str2byt(word As String, Style As Byte)


Dim tpdata() As Byte

tpdata = word

ReDim SendData(UBound(tpdata) + 1) As Byte '发送数据

SendData(0) = Style

CopyMemory SendData(1), tpdata(0), UBound(SendData)

str2byt = SendData

End Function




'数组转换成字串的函数
Function byt2str(byt() As Byte) As String

ReDim tpdata(UBound(byt) - 1) As Byte

CopyMemory tpdata(0), byt(1), UBound(byt)

byt2str = tpdata


End Function




'用来把文件名\大小信息数据放进数组
Function fileinfo2byt(FileSize As Long, Filename As String)

Dim tpdata() As Byte

tpdata = Filename

ReDim SendData(UBound(tpdata) + 5) As Byte

SendData(0) = 4

CopyMemory SendData(1), FileSize, 4

CopyMemory SendData(5), tpdata(0), UBound(tpdata) + 1

fileinfo2byt = SendData


End Function



'把数组中的文件名分离出来
Function byt2filename(byt() As Byte) As String


ReDim tpdata(UBound(byt) - 5) As Byte


CopyMemory tpdata(0), byt(5), UBound(tpdata) + 1

byt2filename = tpdata

Debug.Print byt2filename

End Function



'把数组中的文件大小分离出来
Function byt2filesize(byt() As Byte) As Long

Dim FileSize As Long

CopyMemory FileSize, byt(1), 4

byt2filesize = FileSize

End Function


'发送文件数据请求放进数组
Function gtinfo2byt(getinfo As Long)

ReDim tpdata(4) As Byte

tpdata(0) = 5

CopyMemory tpdata(1), getinfo, 4

gtinfo2byt = tpdata

End Function


'数组中分离出文件数据
Function byt2gtinfo(byt() As Byte) As Long

Dim a As Long

CopyMemory a, byt(1), 4

byt2gtinfo = a

End Function


'把文件数据和信息放数组
Function filedata2byt(byt() As Byte)

ReDim tpdata(UBound(byt) + 1) As Byte

tpdata(0) = 7

CopyMemory tpdata(1), byt(0), UBound(tpdata)

filedata2byt = tpdata


End Function

'把数组中的文件数据分离出来
Function byt2filedata(byt() As Byte)

ReDim tpdata(UBound(byt) - 1) As Byte

CopyMemory tpdata(0), byt(1), UBound(byt)

byt2filedata = tpdata


End Function

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -