我在服务端将文件打开并分块,每块大小是512字节
      dim arr() as byte
      get #1,,arr
      要把arr字节数组传输到客户端,且只能以字符串形式传,
      也就是说怎样把一个字节数组连在一个字符串后?
      请各位高手给以指点?

解决方案 »

  1.   

    XX.send "字串"
    XX.send arr
    接受时
        Dim StrTem As String
        Dim arr() As Byte
        XX.GetData StrTem, vbString, 2
        XX.GetData arr, vbArray + vbByte
      

  2.   

    Dim rec            As New ADODB.RecordsetDim sreFilename    As String          '在发送时 存储  文件名称,写到对应的字段Dim lgMaxfilenb    As Long            '当把文件写入字段后,用  select max(文件号) 返回 刚才 发的 文件号,此号用于通知 收件人 收取 哪个文件
     
     
    '---------------------------------------------------------------------
    '                      写一个文件到数据库字段
    '---------------------------------------------------------------------
    Private Sub WriteBinarytofiled(filename As String)Dim FileNumber   As Long
    Dim FileBuffer() As Byte
    Dim lSize        As Long
    Dim ZSize        As Long
    Dim tfiled As ADODB.Field
       On Error GoTo ercl   '对错误进行处理
              If filename = "" Then Exit Sub
                         lSize = FileLen(filename)
              If lSize = 0 Then Exit Sub
                         ZSize = lSize
     
    '   If lSize > 1000000 Then           '限制文件的大小
    '                      Exit Sub
    '   End If
       
       ProgressBar1.Max = lSize
       ProgressBar1.Value = 0
       
       Const xSize = 1000    '每次写1000个字节
       ReDim FileBuffer(1 To xSize)
       
       
       Screen.MousePointer = 11
      rec.Open "select * from 信箱 where 用户号=0", cnvvv, adOpenKeyset, adLockOptimistic          '用户号=0 是不存在的用户,返回空的记录集  Set tfiled = rec!文件
      rec.AddNew
            FileNumber = FreeFile
            Open filename For Binary Access Read As #FileNumber   '以二进制打开文件
                       '得到文件的长度
                       Do While lSize >= xSize                        '当剩余文件的长度不足1000字节时结束循环
                            Get #FileNumber, , FileBuffer            '读取文件
                            tfiled.AppendChunk FileBuffer            '把文件给予字段
                            lSize = lSize - xSize                    '得到剩余的文件的长度
                            
                            ProgressBar1.Value = ZSize - lSize
                            DoEvents
                        
                       Loop
                       If lSize > 0 Then
                         ReDim FileBuffer(1 To lSize) As Byte          '重新声明  字节数组
                         Get #FileNumber, , FileBuffer                 '读剩余的文件
                         tfiled.AppendChunk FileBuffer                 '把文件给予字段
                         ProgressBar1.Value = ZSize - lSize
                         
                       End If
           Close #FileNumber
           '写其它字段
            rec!文件名.Value = sreFilename           '写文件名
            rec!用户号.Value = lgUserid              '发送人 的 用户号码
            rec!说明.Value = frm_010_Selfiles.Text1.Text & "  "     '附加说明书
            rec!文件类型.Value = GetFileTypeName(filename)
            rec!大小.Value = ZSize / 1000        'KB
            rec!发信日期.Value = Now             '完成时间
            rec.Update
            rec.Close
            
            
            
            
            
            rec.Open "select max(文件号) as 文件号 from 信箱 where 用户号=" & lgUserid, cnvvv
            lgMaxfilenb = rec!文件号
            rec.Close        
            '写 邮寄单--------
             rec.Open "select * from 信件信息 where 用户号=0", cnvvv, adOpenKeyset, adLockOptimistic
      
              For I = 1 To frm_010_Selfiles.ListView2.ListItems.Count
                           
                           rec.AddNew
                           rec!用户号.Value = Val(frm_010_Selfiles.ListView2.ListItems(I).Tag)
                           rec!文件号.Value = lgMaxfilenb
                           rec!状态.Value = "未收"
                           rec!类型.Value = "WJ"
                           rec.Update
              Next I
             rec.Close
            '-----------------
            
        
         Screen.MousePointer = 0
         ProgressBar1.Value = 0
      Exit Sub
    ercl:
         
            Screen.MousePointer = 0
            frm_021_ShowErr.txtErr = "错误信息:" & Err.Description
           
            Err.Clear
    End SubPrivate Sub Command1_Click()
    Dim LL As Integer
    LL = frm_010_Selfiles.ListView1.ListItems.Count
             For I = 1 To LL
                   sreFilename = frm_010_Selfiles.ListView1.ListItems(I).Text
                   Label1.Caption = "共" & LL & "个文件,正在发送第" & I & "个文件  " + sreFilename
                   WriteBinarytofiled frm_010_Selfiles.ListView1.ListItems(I).SubItems(3)
                   frm_010_Selfiles.ListView1.ListItems(I).ForeColor = vbGreen
             Next I
             Beep
             Unload Me
             If I < LL Then frm_022_Msgbox.Label1.Caption = "发送过程出错!"
             frm_022_Msgbox.Label1.Caption = "发送成功!"
             
    End SubPrivate Sub Form_Activate()
    Command1.Value = True
    End Sub
      

  3.   

    '将任何文件从数据库中下载到本地: 
        Public Function LoadFile(ByVal col As ADODB.Field, ByVal FileName As String) As Boolean '获得binary数据 
        On Error GoTo myerr: 
         Dim arrBytes() As Byte 
         Dim FreeFileNumber As Integer 
         lngsize = col.ActualSize 
         arrBytes = col.GetChunk(lngsize) 
         FreeFileNumber = FreeFile 
         Open FileName For Binary Access Write As #FreeFileNumber 
         Put #FreeFileNumber, , arrBytes 
         Close #FreeFileNumber 
         LoadFile = True 
        myerr: 
         If Err.Number <> 0 Then 
         LoadFile = False 
         Err.Clear 
         End If 
        End Function 
         
        '将文件从本地上传到数据库中 
        Public Function UpLoadFile(ByVal FileName, ByVal col As ADODB.Field) As Boolean 
         On Error GoTo myerr: 
         Dim arrBytes() As Byte 
         Dim FreeFileNumber As Integer 
         FreeFileNumber = FreeFile 
         Open FileName For Binary As #FreeFileNumber 
         n = LOF(FreeFileNumber) 
         ReDim arrBytes(1 To n) As Byte 
         Get #FreeFileNumber, , arrBytes 
         Close #FreeFileNumber 
         col.AppendChunk (arrBytes) 
         UpLoadFile = True 
        myerr: 
         If Err.Number <> 0 Then 
         UpLoadFile = False 
         Err.Clear 
         End If 
        End Function