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

  • SEARCH
  • Home
  • 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 6776639
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T16:03:11+00:00 2026-05-26T16:03:11+00:00

I have a new program I am writing in C#, it will need to

  • 0

I have a new program I am writing in C#, it will need to read and write binary files that are compatible with vb6’s binary format. I can not change the vb6 program but I can make changes to my program.

I have everything working except I am a little iffy about strings.

If I write the following in vb6

Private Type PatchRec
   string As String
End Type

Private Sub Command1_Click()
    Dim intFileNum As Integer
    Dim recTest As TestRec
    intFileNum = FreeFile
    Open "E:\testing" & "\" & "testfile" & ".bin" For Binary Access Write As #intFileNum
    recTest.string = "This is a test string"    
    Put #intFileNum, , recPatch
    Close #intFileNum
End Sub

And I write the following in C#

public static void Main(params string[] args)
{
    using(var fs = new FileStream("test.bin", FileMode.Create, FileAccess.ReadWrite))
    using (var bw = new BinaryWriter(fs))
    {
        string str = "This is a test string";
        bw.Write(str);
    }
}

I get these two hex strings

vb6 - 15 00 54 68 69 73 20 69 73 20 61 20 74 65 73 74 20 73 74 72 69 6E 67
c# -     15 54 68 69 73 20 69 73 20 61 20 74 65 73 74 20 73 74 72 69 6E 67

It appears BinaryWriter is not the same between the two when writing strings, vb6 uses a two byte string and C# uses a UTF-7 encoded unsigned int. Also I can not find any resource to what encoding VB is using when it writes a file this way.

Are there any built in tools to write the same way vb6 does and if not other than turning the length in to a uint16 are there any other gotchas I need to be aware of?

  • 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-26T16:03:11+00:00Added an answer on May 26, 2026 at 4:03 pm

    It is simply a short that contains the string length, use BinaryWriter(short). Don’t use BinaryWriter.Write(string), use BinaryWriter.Write(byte[]) where you got the byte[] from Encoding.Default.GetBytes().

    Intentional avoiding the compat functions in the Microsoft.VisualBasic namespace might not the be most productive approach. It doesn’t byte, the framework doesn’t care what language you use. Have a look at Microsoft.VisualBasic.FileSystem.FilePut(). Available in any .NET framework version, that’s code you won’t have to maintain and has been tested by thousands. You do have to add an assembly reference to Microsoft.VisualBasic.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm writing a program that sits in the systray. It will have a keyboard
I am writing a program that will create users in bulk, I have a
I have some code that effectively does this : File file = new File(C:\\Program
I have a program that uses: ThreadPool.QueueUserWorkItem(new WaitCallback(FireAttackProc), fireResult); On Windows7 and Vista it
I'm writing a c# program that will launch many child processes. At some time
I'm writing a program that will take in an equation and check if all
I am writing a program that will allow me to open excel spreadsheets and
I have rewritten an old program and designed a new database for it. I
I have the following code: class Program { static void Main(string[] args) { new
I have a single xml file and every new thread of the program (BHO)

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.