请高手帮助改一下下面代码里的错务,谢谢!!!

msdn165168 2004-07-22 06:07:21
请高手帮助改一下下面代码里的错务,谢谢!!!

我想把编码后的数据赋给数组Outfile(),求高手帮助改一下下面代码里的错务,谢谢!!!
Private Sub Command3_Click()
Dim aaa() As Byte
Call Base64Encode1(App.Path & "\ccc.txt", aaa)
MsgBox aaa
End Sub

Private Function Base64Encode1(infile As String, Outfile() As Byte)
Dim FnumIn As Integer, FnumOut As Integer
Dim mInByte(3) As Byte, mOutByte(4) As Byte
Dim myByte As Byte
Dim aaasa, nmmn
Dim i As Integer, LineLen As Integer, j As Integer
FnumIn = FreeFile()
Open infile For Binary As #FnumIn
While Not EOF(FnumIn)
i = 0
Do While i < 3
Get #FnumIn, , myByte
If Not EOF(FnumIn) Then
mInByte(i) = myByte
i = i + 1
Else
Exit Do
End If
Loop
Base64EncodeByte mInByte, mOutByte, i
For j = 0 To 3
Outfile = Outfile & mOutByte(j)
Next j
LineLen = LineLen + 1
If LineLen * 4 > 70 Then
Outfile = Outfile & vbCrLf
LineLen = 0
End If
Wend
Close (FnumIn)
End Function

Private Sub Base64EncodeByte(mInByte() As Byte, mOutByte() As Byte, num As Integer)
Dim tByte As Byte
Dim i As Integer

If num = 1 Then
mInByte(1) = 0
mInByte(2) = 0
ElseIf num = 2 Then
mInByte(2) = 0
End If

tByte = mInByte(0) And &HFC
mOutByte(0) = tByte / 4
tByte = ((mInByte(0) And &H3) * 16) + (mInByte(1) And &HF0) / 16
mOutByte(1) = tByte
tByte = ((mInByte(1) And &HF) * 4) + ((mInByte(2) And &HC0) / 64)
mOutByte(2) = tByte
tByte = (mInByte(2) And &H3F)
mOutByte(3) = tByte

For i = 0 To 3
If mOutByte(i) >= 0 And mOutByte(i) <= 25 Then
mOutByte(i) = mOutByte(i) + Asc("A")
ElseIf mOutByte(i) >= 26 And mOutByte(i) <= 51 Then
mOutByte(i) = mOutByte(i) - 26 + Asc("a")
ElseIf mOutByte(i) >= 52 And mOutByte(i) <= 61 Then
mOutByte(i) = mOutByte(i) - 52 + Asc("0")
ElseIf mOutByte(i) = 62 Then
mOutByte(i) = Asc("+")
Else
mOutByte(i) = Asc("/")

End If
Next i

If num = 1 Then
mOutByte(2) = Asc("=")
mOutByte(3) = Asc("=")
ElseIf num = 2 Then
mOutByte(3) = Asc("=")
End If
End Sub
...全文
147 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
menghun1355 2004-07-22
  • 打赏
  • 举报
回复
改:Outfile = Trim(Outfile) & Trim(mOutByte(j))
Outfile = Trim(Outfile) & vbCrLf
csdnchenxu 2004-07-22
  • 打赏
  • 举报
回复
实在搞不懂楼主的代码啊 MsgBox aaa 有什么含义
而且Private Function Base64Encode1(infile As String, Outfile() As Byte)
Outfile() 是不是要加 byref ??

对于错误的地方建议方法:

For j = 0 To 3
ReDim Preserve Outfile(UBound(Outfile) + j + 1)
Outfile(UBound(Outfile) + j + 1) = mOutByte(j)
Next j
LineLen = LineLen + 1
If LineLen * 4 > 70 Then
ReDim Preserve Outfile(UBound(Outfile) + 1)
Outfile(UBound(Outfile) + 1) = vbCrLf
wychero 2004-07-22
  • 打赏
  • 举报
回复
Up
chenyu5188 2004-07-22
  • 打赏
  • 举报
回复
UP
northwolves 2004-07-22
  • 打赏
  • 举报
回复
Outfile() As Byte

Outfile = Outfile & mOutByte(j)

Outfile = Outfile & vbCrLf

以上用法不对,好象 Outfile 为 string类型可以这样处理
dongge2000 2004-07-22
  • 打赏
  • 举报
回复
帮顶!

7,762

社区成员

发帖
与我相关
我的任务
社区描述
VB 基础类
社区管理员
  • VB基础类社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧