Results 1 to 16 of 16

Thread: [2005] File IO Problem

Hybrid View

  1. #1
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: [2005] File IO Problem

    Well I just want to start from the code execution on down. So the next line will be ....

    Code:
    Map(MapNum) = Reader.ReadBytes(Stream.Length)
    So to convert this, its basically just a class with some variables. Seems like you are trying to read a file and populate the class at the same time?
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  2. #2

    Thread Starter
    Addicted Member Gonegaming12's Avatar
    Join Date
    Jun 2006
    Location
    USA
    Posts
    131

    Re: [2005] File IO Problem

    exactly, i'm trying to read the file straight into the class, and vise-versa for the savelocalmap method.

    I read around the internet about this and I think i have it, i should use serialization with my classes.

    Code:
        Sub LoadMap(ByVal MapNum As Integer)
            Dim FileName As String
    
            FileName = Application.StartupPath & "\maps\map" & MapNum & ".dat"
    
            If FileExist(FileName) = False Then Exit Sub
    
            Dim input As IO.FileStream
            Dim reader As Runtime.Serialization.Formatters.Binary.BinaryFormatter = New Runtime.Serialization.Formatters.Binary.BinaryFormatter()
    
            input = New IO.FileStream(FileName, IO.FileMode.Open, IO.FileAccess.Read)
    
            Try
                Map(MapNum) = CType(reader.Deserialize(input), MapRec)
            Catch serializableException As Runtime.Serialization.SerializationException
                input.Close()
    
            End Try
    
            input.Close()
    
        End Sub
    thats my code now, but im getting an error, let me bring it up again...just a sec...

    The input stream is not a valid binary format. The starting contents (in bytes) are: 20-20-20-20-20-20-20-20-20-20-20-20-20-20-20-20-20 ...

    for line

    Code:
    Map(MapNum) = CType(reader.Deserialize(input), MapRec)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width