请帮我修改个错误,同时看看我的代码还有什么问题

busy2005 2005-09-19 08:20:42
以下是我写的发送文件的一段代码,其中协议只是给每一包文件加了个表示长度的头,还没有写完,
提示错误出现在 Get #intfilenumber, , bytfilebuffer(intfilelenth)语句 错误为“变量使用了一个vb不支持的自动化类型”, 我不知道是怎么回事 求大哥大姐帮帮忙指点指点!

Public Sub FileSendManager(filename As String)

Dim byttest(8) As Byte
Dim bytSend() As Byte
Dim intSendLen As Long
Dim intfilelenth As Long
Dim filebuffer() As Byte
Dim intfilenumber As Integer
Dim intfilecount As Integer, i As Integer, j As Integer

Dim lperunit As Long

lperunit = 10

filename = Form3.Text1.Text
intfilenumber = FreeFile
Open filename For Binary As intfilenumber '打开文件



intfilelenth = LOF(intfilenumber) '获得文件长度,以字节为单位

ReDim bytfilebuffer(intfilelenth)
Get #intfilenumber, , bytfilebuffer(intfilelenth) '将文件读入缓冲区


If intfilelenth < lperunit Then
MsgBox "文件太小!"
End If

'根据每一块大小获取总包数
If CInt(intfilelenth / lperunit) > intfilelenth / lperunit Then
intfilecount = CInt(intfilelenth / lperunit)
Else: intfilecount = CInt(intfilelenth / lperunit) + 1
End If



For i = 0 To intfilecount - 1

'帧头需修改
byttest(0) = i \ 1000 '组织帧头
byttest(1) = (i Mod 1000) \ 100
byttest(2) = (i Mod 1000 Mod 100) \ 10
byttest(3) = i - byttest(0) * 1000 - byttest(1) * 100 - byttest(2) * 10
byttest(4) = intfilecount \ 1000
byttest(5) = (intfilecount Mod 1000) \ 100
byttest(6) = (intfilecount Mod 1000 Mod 100) \ 10
byttest(7) = intfilecount - byttest(4) * 1000 - byttest(5) * 100 - byttest(6) * 10


Form1.MSComm1.Output = byttest '发送数据
ReDim bysend(lperunit)
For j = 0 To lperunit - 1

bysend(j) = bytfilebuffer(i * lperunit + j)

Form1.MSComm1.Output = bysend
Next
Next


End Sub
...全文
133 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
busy2005 2005-09-20
  • 打赏
  • 举报
回复
如果真的不行 , 我还有其他方法把文件内容读到数组bytfilebuffer() 中吗??

不过还是希望问题能得到解决 帮我查找一下原因
busy2005 2005-09-20
  • 打赏
  • 举报
回复
错误号是“实时错误458”,高手帮我看看怎么改!! 小弟很急 在线等! 同时看看其他部分有没有什么错误。
busy2005 2005-09-20
  • 打赏
  • 举报
回复
楼上的是不是也只是加了 Dim bytfilebuffer() As Byte 这句啊?

别的修改什么了吗? 我怎么看不出来? 楼下的帮我看看!谢谢
northwolves 2005-09-19
  • 打赏
  • 举报
回复
Public Sub FileSendManager(filename As String)

Dim byttest(8) As Byte
Dim bytSend() As Byte
Dim bytfilebuffer() As Byte
Dim intSendLen As Long
Dim intfilelenth As Long
Dim filebuffer() As Byte
Dim intfilenumber As Integer
Dim intfilecount As Integer, i As Integer, j As Integer

Dim lperunit As Long

lperunit = 10

filename = Form3.Text1.Text
intfilenumber = FreeFile
Open filename For Binary As intfilenumber '打开文件



intfilelenth = LOF(intfilenumber) '获得文件长度,以字节为单位

ReDim bytfilebuffer(intfilelenth)
Get #intfilenumber, , bytfilebuffer() '将文件读入缓冲区


If intfilelenth < lperunit Then
MsgBox "文件太小!"
End If

'根据每一块大小获取总包数
If CInt(intfilelenth / lperunit) > intfilelenth / lperunit Then
intfilecount = CInt(intfilelenth / lperunit)
Else: intfilecount = CInt(intfilelenth / lperunit) + 1
End If



For i = 0 To intfilecount - 1

'帧头需修改
byttest(0) = i \ 1000 '组织帧头
byttest(1) = (i Mod 1000) \ 100
byttest(2) = (i Mod 1000 Mod 100) \ 10
byttest(3) = i - byttest(0) * 1000 - byttest(1) * 100 - byttest(2) * 10
byttest(4) = intfilecount \ 1000
byttest(5) = (intfilecount Mod 1000) \ 100
byttest(6) = (intfilecount Mod 1000 Mod 100) \ 10
byttest(7) = intfilecount - byttest(4) * 1000 - byttest(5) * 100 - byttest(6) * 10


Form1.MSComm1.Output = byttest '发送数据
ReDim bysend(lperunit)
For j = 0 To lperunit - 1

bysend(j) = bytfilebuffer(i * lperunit + j)

Form1.MSComm1.Output = bysend
Next
Next
busy2005 2005-09-19
  • 打赏
  • 举报
回复
大家都帮忙看看问题可能出在哪里

帮小弟顶一下!
busy2005 2005-09-19
  • 打赏
  • 举报
回复
还是不行,提示错误和前面的一样,也在那里!

还有 刚才说的加的包头表示的是第几包数据
province_ 2005-09-19
  • 打赏
  • 举报
回复
bytfilebuffer没定义啊。你只定义了filebuffer

7,763

社区成员

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

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