Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6542397
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T11:13:21+00:00 2026-05-25T11:13:21+00:00

I have this code Open WritingPath & \FplDb.txt For Random As #1 Len =

  • 0

I have this code

  Open WritingPath & "\FplDb.txt" For Random As #1 Len = Len(WpRec)
    For i = 1 To 99
      WpRec.WpIndex = FplDB(i, 1)
      WpRec.WpName = FplDB(i, 2)
      WpRec.WpLat = FplDB(i, 3)
      WpRec.WpLon = FplDB(i, 4)
      WpRec.WpLatDir = FplDB(i, 5)
      WpRec.WpLonDir = FplDB(i, 6)
      Put #1, i, WpRec
   Next i
   Close #1
   SaveOk = 1
   FplSave = SaveOk
   Exit Function

This function makes binary serialization of a matrix of 99 structs (WpRec) to file, using “Open” and “Put” statements. But I didn’t get how it is encoded… It is important to me because I need to rewrite the same serialization in C# but I need to know what encoding method is used for that so I can do the same in C#….

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T11:13:22+00:00Added an answer on May 25, 2026 at 11:13 am

    The tricky bit in VB6 was that you were allowed to declare structures with fixed length strings so that you could write records containing strings that didn’t need a length prefix. The length of the string buffer was encoded into the type instead of needing to be written out with the record. This allowed for fixed size records. In .NET, this has kind of been left behind in the sense that VB.NET has a mechanism to support it for backward compatibility, but it’s not really intended for C# as far as I can tell: How to declare a fixed-length string in VB.NET?.

    .NET seems to have a preference for generally writing out strings with a length prefix, meaning that records are generally variable-length. This is suggested by the implementation of BinaryReader.ReadString.

    However, you can use System.BitConverter to get finer control over how records are serialized and de-serialized as bytes (System.IO.BinaryReader and System.IO.BinaryWriter are probably not useful since they make assumptions that strings have a length prefix). Keep in mind that a VB6 Integer maps to a .NET Int16 and a VB6 Long is a .Net Int32. I don’t know exactly how you have defined your VB6 structure, but here’s one possible implementation as an example:

    class Program
    {
      static void Main(string[] args)
      {
         WpRecType[] WpRec = new WpRecType[3];
         WpRec[0] = new WpRecType();
         WpRec[0].WpIndex = 0;
         WpRec[0].WpName = "New York";
         WpRec[0].WpLat = 40.783f;
         WpRec[0].WpLon = 73.967f;
         WpRec[0].WpLatDir = 1;
         WpRec[0].WpLonDir = 1;
         WpRec[1] = new WpRecType();
         WpRec[1].WpIndex = 1;
         WpRec[1].WpName = "Minneapolis";
         WpRec[1].WpLat = 44.983f;
         WpRec[1].WpLon = 93.233f;
         WpRec[1].WpLatDir = 1;
         WpRec[1].WpLonDir = 1;
         WpRec[2] = new WpRecType();
         WpRec[2].WpIndex = 2;
         WpRec[2].WpName = "Moscow";
         WpRec[2].WpLat = 55.75f;
         WpRec[2].WpLon = 37.6f;
         WpRec[2].WpLatDir = 1;
         WpRec[2].WpLonDir = 2;
         byte[] buffer = new byte[WpRecType.RecordSize];
         using (System.IO.FileStream stm = 
            new System.IO.FileStream(@"C:\Users\Public\Documents\FplDb.dat",
            System.IO.FileMode.OpenOrCreate, System.IO.FileAccess.ReadWrite))
         {
            WpRec[0].SerializeInto(buffer);
            stm.Write(buffer, 0, buffer.Length);
            WpRec[1].SerializeInto(buffer);
            stm.Write(buffer, 0, buffer.Length);
            WpRec[2].SerializeInto(buffer);
            stm.Write(buffer, 0, buffer.Length);
    
            // Seek to record #1, load and display it
            stm.Seek(WpRecType.RecordSize * 1, System.IO.SeekOrigin.Begin);
            stm.Read(buffer, 0, WpRecType.RecordSize);
            WpRecType rec = new WpRecType(buffer);
            Console.WriteLine("[{0}] {1}: {2} {3}, {4} {5}", rec.WpIndex, rec.WpName,
               rec.WpLat, (rec.WpLatDir == 1) ? "N" : "S",
               rec.WpLon, (rec.WpLonDir == 1) ? "W" : "E");
         }
      }
    }
    
    class WpRecType
    {
      public short WpIndex;
      public string WpName;
      public Single WpLat;
      public Single WpLon;
      public byte WpLatDir;
      public byte WpLonDir;
    
      const int WpNameBytes = 40; // 20 unicode characters
      public const int RecordSize = WpNameBytes + 12;
    
      public void SerializeInto(byte[] target)
      {
         int position = 0;
         target.Initialize();
         BitConverter.GetBytes(WpIndex).CopyTo(target, position);
         position += 2;
         System.Text.Encoding.Unicode.GetBytes(WpName).CopyTo(target, position);
         position += WpNameBytes;
         BitConverter.GetBytes(WpLat).CopyTo(target, position);
         position += 4;
         BitConverter.GetBytes(WpLon).CopyTo(target, position);
         position += 4;
         target[position++] = WpLatDir;
         target[position++] = WpLonDir;
      }
    
      public void Deserialize(byte[] source)
      {
         int position = 0;
         WpIndex = BitConverter.ToInt16(source, position);
         position += 2;
         WpName = System.Text.Encoding.Unicode.GetString(source, position, WpNameBytes);
         position += WpNameBytes;
         WpLat = BitConverter.ToSingle(source, position);
         position += 4;
         WpLon = BitConverter.ToSingle(source, position);
         position += 4;
         WpLatDir = source[position++];
         WpLonDir = source[position++];
      }
    
      public WpRecType()
      {
      }
    
      public WpRecType(byte[] source)
      {
         Deserialize(source);
      }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a question. This code open fine the txt files with english text,
I have this code to open multiple files one at a time that is
I have this code, I open a stream (without closing or disposing it), then
I have this code: s(x => x.Open()); s is a method which calls one
I have this code in userpage.php: <script langauge=JavaScript><!-- function newWindow(fileName,windowName) { msgWindow=window.open(fileName,windowName); } //--></script>
I have this small code library that I'm considering releasing into Open Source. I
I have a problem with this is code: Set oXmlHTTP = CreateObject(Microsoft.XMLHTTP) oXmlHTTP.Open POST,
In VS 2005, I have some code that looks like this: ifs.open(foo); while (!ifs.eof())
I have this code, which open new jquery-ui dialog and then hide the dialog's
I have this code. xmlhttp.open(GET,getuser.php?q=+str,true); where q=+str I want to pass a second var

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.