473,804 Members | 3,057 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

vb binary file into c++ array

1,646 Top Contributor
I have a very large binary file saved from a vb array with 2 dimensions;
Expand|Select|Wrap|Line Numbers
  1. Dim arMatrix() As Byte
  2. Dim fNum As Integer
  3. ReDim arMatrix(7166, 17769)
  4.  
  5. 'code here to store data from a database into this
  6. 'array
  7.  
  8. 'get a free file number
  9. fNum = FreeFile()
  10.  
  11. 'open the binary file
  12. Open strMatrix For Binary As #fNum
  13.  
  14. 'store the matrix array
  15. Put #fNum, , arMatrix
  16. Close #fNum
When I read the binary data back into the array it works. (i check the data against a database which was the origin of the binary file)

Expand|Select|Wrap|Line Numbers
  1. Dim arMatrix() As Byte
  2. Dim fNum As Integer
  3. ReDim arMatrix(7166, 17769)
  4.  
  5. fNum = FreeFile
  6.     Open "C:\Data\matrix" & Format(lngMatrix, "00") & ".bin" For Binary As #fNum
  7.     Get #fNum, , arMatrix
  8.     Close #fNum
If, instead of a bi-dimensional array, I read this file into a single dimension array with 7167 * 17770 elements the code works but the data is not in the right order.

Expand|Select|Wrap|Line Numbers
  1. Dim arMatrix() As Byte
  2. Dim fNum As Integer
  3. ReDim arMatrix((7167 * 17770) - 1)
  4.  
  5. fNum = FreeFile
  6.     Open "C:\Data\matrix" & Format(lngMatrix, "00") & ".bin" For Binary As #fNum
  7.     Get #fNum, , arMatrix
  8.     Close #fNum
This wrong order also appears when I try to read the same binary data into a c++ array as in:

Expand|Select|Wrap|Line Numbers
  1. void CMFCNetflixDlg::OntxtTestMatrix() 
  2. {
  3.     ifstream f ("C:\\Data\\matrix01.bin", ios::in | ios::binary);
  4.     streambuf * fb;
  5.     int counter;
  6.     fb = f.rdbuf();
  7.  
  8.     char **arMatrix;
  9.     arMatrix = new char *[7167] ;
  10.     for( int i = 0 ; i < 7167 ; i++ )
  11.         arMatrix[i] = new char[17770];
  12.  
  13.     char buff[2];
  14.     char title[10];
  15.  
  16.     for (counter = 0; counter < 7167; counter++) {
  17.  
  18.          fb->sgetn(reinterpret_cast<char *>(arMatrix[counter]), 17770);
  19.  
  20.     }
  21.  
  22.     f.close();
  23.  
  24.                 //testing the order of bytes
  25.     for (i = 0; i < 17770; i++) {
  26.         if ((arMatrix)[0][i]) {
  27.             itoa((int)(arMatrix)[0][i], buff, 10);
  28.             itoa(i, title, 10);
  29.             MessageBox(buff, title);    
  30.         }
  31.     }
  32.     delete [] arMatrix;
  33.  
  34. }
Any ideas on how to open this file so that the bytes are in the right order?

Thanks
Nov 29 '06 #1
1 2314
Banfa
9,065 Recognized Expert Moderator Expert
Clearly vB is writing the data of a 2 dimensional arry to the file in a strange order.

I would say that you options are

1. Work out what that strange order is an write some code to read the file contents into the single dimensioned buffer correctly.

2. Alter the code that writes the data so that instead of writing the entire array it writes individual entries in the arry in an order specified by yourself (and therefore readable by yourself).
Nov 29 '06 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

7
728
by: Arnold | last post by:
I need to read a binary file and store it into a buffer in memory (system has large amount of RAM, 2GB+) then pass it to a function. The function accepts input as 32 bit unsigned longs (DWORD). I can pass a max of 512 words to it at a time. So I would pass them in chunks of 512 words until the whole file has been processed. I haven't worked with binary files before so I'm confused with how to store the binary file into memory. What sort of...
5
5566
by: rob | last post by:
hey every1, I've got alot of data to write out to file and it's all just 1's and 0's. It's all stored in 2 dimensional arrays of width 32 and varying height. At the moment it's all just integer arrays and the individual 1's and 0's are being written out as integers.
8
9538
by: Yeow | last post by:
hello, i was trying to use the fread function on SunOS and ran into some trouble. i made a simple test as follows: i'm trying to read in a binary file (generated from a fortran code) that contains the following three floating-point numbers: 1.0 2.0 3.0
4
5642
by: Jens Mittag | last post by:
Hi! In my code, I have an array of a structure, which I want to save to a binary file. When the array is just created, everything works fine, but when I change contents of the array, saving results in a file, which doesn't hold the information of the changed array anymore. I dont know why. Here is the code: /*
7
6065
by: John Dann | last post by:
I'm trying to read some binary data from a file created by another program. I know the binary file format but can't change or control the format. The binary data is organised such that it should populate a series of structures of specified variable composition. I have the structures created OK, but actually reading the files is giving me an error. Can I ask a simple question to start with: I'm trying to read the file using the...
8
8934
by: Mark | last post by:
Hello. I am attempting to write binary data from a file to an OLE Object field, and then write the file back out from the database. I am reading and writing the files in binary mode, and using GetChunk and AppendChunk to read and write binary data from the OLE Object field. I am using VBA and DAO for this experiment. The OLE Object field is being used to store Long Binary data.
2
13132
by: Edvin | last post by:
Why is binary array written to a file different than when converting the binary array to string and then writing it to file! For example: // --- Allocate byte array byte arrByte = new byte; for( int i=1; i< arrByte.Length; i++ ) arrByte = (byte)i;
3
3199
by: nguser3552 | last post by:
Hello Everyone, I have a problem I can't surmount, anything is gravy at this point. I need to be able to read any type of file .ext (mov,mpeg,mp3,etc) in binary format. I can do this in C, but have to use: int main(int argc,char** argv) which is archaic. My compiler is Visual Studio 5.0 Pro. To make my dilemma as clear as possible:
5
11281
by: dm3281 | last post by:
Hello, I have a text report from a mainframe that I need to parse. The report has about a 2580 byte header that contains binary information (garbage for the most part); although there are a couple areas that have ASCII text that I need to extract. At the end of the 2580 bytes, I can read the report like a standard text file. It should have CR/LF at the end of each line. What is the best way for me to read this report using C#. It is...
0
9706
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9584
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10337
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
7622
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6854
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5525
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5654
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4301
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3822
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.