用VB做局域网内部通讯
我现在想在局域网内实现点对点的互发文件功能。我用的是winsock控件,用TCP协议。现在的问题是:我运行程序是回出现:“运行错误‘9’。下标越界。”这是怎么回事啊?Private Sub sendfile_Click()
Dim myfile() As Byte
Dim position As Long
'For i = 0 To Num
With CommonDialog1
.DialogTitle = "打开文件"
.InitDir = "E:\"
.Filter = "所有文件(*.*)|*.*"
.FilterIndex = 1
.ShowOpen
Open .FileName For Binary As #1
End With
position = 0
ReDim Preserve myfile(1 To position)
Do While Not EOF(1)
position = positon + 1
Get #1, , myfile(position)
Loop
Close #1
tcpServer(i).SendData "1" & myfile(position)
Textmsg.SelStart = Len(Textmsg.Text)
Textmsg.Text = Textmsg.Text + Chr(10) + "server:" + Textsend.Text
Textsend.Text = ""
End Sub
我这段代码有没有什么错误啊?
--------------------编程问答-------------------- 文件中是否有中文? --------------------编程问答-------------------- position = 0
ReDim Preserve myfile(1 To position)
这两句连在一起,相当于只 ReDim Preserve myfile(1 To 0)
--------------------编程问答-------------------- position = 0
ReDim Preserve myfile(1 To Lof(1))
Do While Not EOF(1)
position = positon + 1
Get #1, , myfile(position)
Loop --------------------编程问答-------------------- 如果把”ReDim Preserve myfile(1 To position) “
放在 ”position = positon + 1 “后面,行不行的 啊?
--------------------编程问答-------------------- -----------
position = 0
ReDim Preserve myfile(1 To position)
Do While Not EOF(1)
position = positon + 1
Get #1, , myfile(position)
Loop
-------
改为
position=0
ReDim Preserve myfile(1 To Lof(1))
Get #1,, myfile
补充:VB , 控件