Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/vb.net/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
VB.NET中的VB 6.0二进制读写_Vb.net_Vb6_Binaryreader - Fatal编程技术网

VB.NET中的VB 6.0二进制读写

VB.NET中的VB 6.0二进制读写,vb.net,vb6,binaryreader,Vb.net,Vb6,Binaryreader,我有一个vb.net代码,想在vb 6.0中转换它。但是我有一些困难。我找不到与某些.net类相当的类 Dim byteswritten As Integer Dim fs As System.IO.FileStream Dim r As System.IO.BinaryReader Dim CHUNK_SIZE As Integer = 65554 fs = New Syst

我有一个vb.net代码,想在vb 6.0中转换它。但是我有一些困难。我找不到与某些.net类相当的类

            Dim byteswritten As Integer
            Dim fs As System.IO.FileStream
            Dim r As System.IO.BinaryReader
            Dim CHUNK_SIZE As Integer = 65554
            fs = New System.IO.FileStream(filePath, System.IO.FileMode.Open, System.IO.FileAccess.Read)
            r = New System.IO.BinaryReader(fs)
            Dim FSize As Integer = CType(fs.Length, Integer)
            Dim chunk() As Byte = r.ReadBytes(CHUNK_SIZE)

            While (chunk.Length > 0)
                dmPutStream.Write(chunk, chunk.Length, byteswritten)
                If (FSize < CHUNK_SIZE) Then
                    CHUNK_SIZE = FSize
                    chunk = r.ReadBytes(CHUNK_SIZE)
                Else
                    chunk = r.ReadBytes(CHUNK_SIZE)
                End If
             End While
Dim字节写入整数
将fs设置为System.IO.FileStream
Dim r As System.IO.BinaryReader
Dim CHUNK_大小为整数=65554
fs=New System.IO.FileStream(filePath、System.IO.FileMode.Open、System.IO.FileAccess.Read)
r=新System.IO.BinaryReader(fs)
Dim FSize As Integer=CType(fs.Length,Integer)
Dim chunk()为Byte=r.ReadBytes(块大小)
While(chunk.Length>0)
dmPutStream.Write(chunk,chunk.Length,byteswrite)
如果(FSize
嗯,文档可能会很大,然后我们使用块。但是我不知道VB6.0的步骤


比如我应该怎么读二进制文件

将VB.NET转换为VB6是个坏主意,完全没有必要。如果需要使用VB6应用程序中的VB.NET代码,最好为.NET库创建一个COM可见包装,并从VB6应用程序调用该包装

您可能可以使用VB6在功能上转换代码,但实际上没有意义。NET是一种比VB6更好的语言,使用它的COM功能可以避免编写冗长的VB6代码

如果您死心塌地地想这么做,那么您将需要在功能上重现流和读卡器类

以下是FileStream.cs的源代码:

对于BinaryReader:
将VB.NET转换为VB6是个坏主意,完全没有必要。如果需要使用VB6应用程序中的VB.NET代码,最好为.NET库创建一个COM可见包装,并从VB6应用程序调用该包装

您可能可以使用VB6在功能上转换代码,但实际上没有意义。NET是一种比VB6更好的语言,使用它的COM功能可以避免编写冗长的VB6代码

如果您死心塌地地想这么做,那么您将需要在功能上重现流和读卡器类

以下是FileStream.cs的源代码:

对于BinaryReader:
如果没有打开写流和关闭读写流的所有代码,下面是一个如何在VB6中使用ADODB.stream执行此操作的示例

Project | References
下,添加对
ADO Active X数据对象库的引用。我的版本是6.1,但您可以选择最新版本-这取决于您的系统上安装的ADO版本

希望有帮助-如果你想查看所有的


如果没有打开写流和关闭读写流的所有代码,下面是一个如何在VB6中使用ADODB.stream执行此操作的示例

Project | References
下,添加对
ADO Active X数据对象库的引用。我的版本是6.1,但您可以选择最新版本-这取决于您的系统上安装的ADO版本

希望有帮助-如果你想查看所有的


VB.NET->VB6对我来说听起来是个坏主意。如果您需要在VB6中使用此功能,请使用.NET代码创建一个程序集,并将其注册为COM互操作-无需重新编写我们在VB6.0中有一个工具,我必须更改一些代码,但此部分在vb.NET中不存在,那么我必须在vb 6中执行此操作。vb.NET->VB6的可能重复对我来说听起来是个坏主意。如果您需要在VB6中使用此功能,请从.NET代码创建程序集,并将其注册为COM互操作-无需重新编写我们在VB6.0中有一个工具,我必须更改一些代码,但此部分在vb.NET中不存在,那么我必须在vb 6中执行此操作可能重复
Public Sub StreamData(strWriteFilename As String, filePath As String)

    Const CHUNK_SIZE As Long = 65554

    Dim byteswritten    As Integer
    Dim FSize           As Long

    Dim adofs           As New ADODB.Stream 'Object 'System.IO.FileStream
    Dim varData         As Variant

    ' Include this here - but probably defined elsewhere
    Dim dmPutStream     As New ADODB.Stream

    ' Open Write Stream
    ' *** Looks like you do this elsewhere
    Set dmPutStream = CreateObject("ADODB.Stream")
    With dmPutStream
        .Type = adTypeBinary
        .Open strWriteFilename, adModeWrite
    End With

    ' Open Read strema and start pushing data from it to the write stream
    Set adofs = CreateObject("ADODB.Stream") 'New System.IO.FileStream(filePath, System.IO.FileMode.Open, System.IO.FileAccess.Read)
    With adofs
        .Type = adTypeBinary
        .Open
        .LoadFromFile filePath

        ' Size of Read file - do you want this?
        FSize = .Size

        varData = .Read(CHUNK_SIZE)
        Do While Len(varData) > 0
            dmPutStream.Write varData
            If Not .EOS Then
                varData = .Read(CHUNK_SIZE)
            End If
        Loop

        .Close
    End With

    'Save binary data To disk
    dmPutStream.SaveToFile strWriteFilename, adSaveCreateOverWrite
    dmPutStream.Close

End Sub