Note that there are some explanatory texts on larger screens.

plurals
  1. POConversion from VB6 string data to .NET byte array
    primarykey
    data
    text
    <p>I'm writing a C# application that reads data from an SQL database generated by VB6 code. The data is an array of Singles. I'm trying to convert them to a float[]</p> <p>Below is the VB6 code that wrote the data in the database (cannot change this code):</p> <pre><code> Set fso = New FileSystemObject strFilePath = "c:\temp\temp.tmp" ' Output the data to a temporary file intFileNr = FreeFile Open strFilePath For Binary Access Write As #intFileNr Put #intFileNr, , GetSize(Data, 1) Put #intFileNr, , GetSize(Data, 2) Put #intFileNr, , Data Close #intFileNr ' Read the data back AS STRING Open strFilePath For Binary Access Read As #intFileNr strData = String$(LOF(intFileNr), 32) Get #intFileNr, 1, strData Close #intFileNr Call Field.AppendChunk(strData) </code></pre> <p>As you can see, the data is put in a temporary file, then read back as VB6 String and wrote in the database (row of type dbLongBinary)</p> <p>I've tried the following:</p> <p>Doing a BlockCopy</p> <pre><code>byte[] source = databaseValue as byte[]; float [,] destination = new float[BitConverter.ToInt32(source, 0), BitConverter.ToInt32(source, 4)]; Buffer.BlockCopy(source, 8, destination, 0, 50 * 99 * 4); </code></pre> <p>The problem here is the VB6 binary to string conversion. The VB6 string char is 2 bytes wide and I don't know how to transform this back to a binary format I can handle.</p> <p>Below is a dump of the temp file that the VB6 code generates: <a href="http://robbertdam.nl/share/dump%20of%20text%20file%20generated%20by%20VB6.png" rel="nofollow noreferrer">alt text http://robbertdam.nl/share/dump%20of%20text%20file%20generated%20by%20VB6.png</a></p> <p>And here is the dump of the data as I read it from the database in (=the VB6 string): <a href="http://robbertdam.nl/share/dump%20of%20database%20field.png" rel="nofollow noreferrer">alt text http://robbertdam.nl/share/dump%20of%20database%20field.png</a></p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload