Tracking Forums, Newsgroups, Maling Lists
Home Scripts Tutorials Tracker Forums
 
  HOME    TRACKER    Visual Basic




How To Write Binary(bmp) Data To A File?


Hi All,I am trying to write binary data to a file, which is bmp image:Open "d: emp est001.bmp" For Binary Access Write As #1Put #1, 1, strImageClose #1*** strImage contains binary datawhen i try to open the bmp it show invalid bitmap file.Appreciate if anyone can help.Thankskee




View Complete Forum Thread with Replies

See Related Forum Messages: Follow the Links Below to View Complete Thread
Does ANYONE Know How To Write Binary Data From SQL To A File?
I am storing documents, pdfs and images in SQL as binary data. I am trying to read the data from ASP and write it to a file on my machine. In short, I'm trying to transfer files from SQL to my machine without having to click save-as on the webpage.

Does anyone know how to do this?

Any help would be GREATLY appreciated.

Write And Shift Data In Binary File
Hello, I have a lot of binary files that I need to fix. The end of the binary files look like this:


Code:
[3]'Draw a card?'
[4]'Make a bet?'
[5]'You have won!' (c)TG+  ‰¿ˆ


Code:
[3]'Pause the game!'
[4]'Stop the game!'
[5]'Select a new opponent!'



(c)TR+  ô½É


I need to keep all the data and write "{aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa}" between the normal text and "(c)TG+  ‰¿ˆ", so it looks like this:


Code:
[3]'Draw a card?'
[4]'Make a bet?'
[5]'You have won!'

{aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa} (c)TG+  ‰¿ˆ


Code:
[3]'Pause the game!'
[4]'Stop the game!'
[5]'Select a new opponent!'



{aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa} (c)TR+  ô½É


"{aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa}" has to start on a new line and there has to be a space between "}" and "(".
The text in the binary file and the data at the end are always different. Only "(c)" is always the same, so I have to focus on that.

The problem with writing to a binary file is that data gets overwritten and not shifted. Does anybody know how to do this?


vb Code:
Private Sub Command1_Click()Dim tmp As String, strString As String, y As Long, FilePos As LongDim Buffer() As Byte    ReDim Preserve Buffer(100)    Open tmp For Binary As #1      FilePos = LOF(1) - 100      Get #1, FilePos, Buffer              strString = StrConv(Buffer, vbUnicode)                    y = InStr(1, strString, "(c)", vbBinaryCompare)          If y <> 0 Then              Put #1, LOF(1) - 100 + x, vbCrLf & vbCrLf & "{aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa}"          End If    Close #1 End Sub

How To Read/write Binary Data To A File
Hi all,

How do I read/write binary data to/from a file. I dont want the user toopen the file in notepad/wordpad and read the contents

Regards,
MRL

Write Text Data To A Binary File (Also Read It Back)
Hey all.

Ii have an app that uses an array to hold text data (many reasons for this, but it is the way it is).

In any case, I encrypt the data using an AES_Rijndael Block Cipher, all is well.

I would now like to write this data to a BINARY file (I cannot do so to a text file as part of the encrypted data may contain the vbCRLF char set).

Ii need to also be able to read thebinary data back into my app, then populate an array with the DECRYPTED data (I have the encryption and decryption routines already working).

How can one do this?

Thanks.

Read And Write Binary Data Files
Hi. I need to read and write some binary data files (don`t ask why) from a software made in Turbo Pascal 7 into my VB application.(I know the record structure) My point is, How do I open the file and read a record?. I now there is "OPEN FOR " command and how to use it but only with random files. Any help. Or documentation. Or any link? Thanks.

Binary Write With Custom Data Types
Hi all,

I'm trying to save my custom datatype in a file

Public AllResults() As udtResults
Public Type udtResults
strItem As String
strmessage As String
blnSuccess As Boolean
enumStage As Stage
End Type
Public Enum Stage
PartGeneration = 0
fetched = 1
ConvertedStage1 = 2
ConvertedStage2 = 3
Updated = 4
End Enum

During the lifetime the program populate the allresults() array with information about certain process. But when i try to write the info into a file with the following function i get an error message "Compile error. Can't Get or Put an object reference variable or a variable of user-defined type containing an object reference". I suspect this is happening because Ive got an enum type defined inside of udtresults. Is there an other way to perform an operation similar to binary write (using apis for example).

Private Sub SaveResults(strResultFile As String)
Dim i As Integer
Dim result As udtResults
Open strResultFile For Binary Access Write As #1 Len = Len(result)
For i = 1 To UBound(AllResults)
result = AllResults(i)
Put #1, , result
Next i
Close #1
End Sub

Write/send Data Like Binary (1/0 ) Via Usb Port
hey guys.. i need vb source code to send data or vb result via usp port.. Any body know? Help me please.. My thesis deadline is about 1 week later.. Thx a lot for your help..

Binary File Write
I have 2 questions:

1. I want to open a file and save it without the last 128 bytes (so the file will be 128 bytes shorter. Can someone help me with the syntax to do this?

2. Similar to question1, but save the file without the first 128 bytes.


Thanks to anyone for help.

Write UDT To Binary File
I have a UDT that I would like to simply dump into a binary file...and there's other stuff dumped into the file as well. What do I need to do to dump the UDT...and read it back in, for that matter? Thanks in advance!

Write Binary File
Yo. I'm using a winsock control to connect to a server and download a file. Here's what I have after I'm connected:

Code:
Private Sub sckDownload_DataArrival(ByVal bytesTotal As Long)
Dim strWang As String
sckDownload.GetData strWang$, vbString
Open "C:download.dat" For Binary As #2
Put #2, , strWang$
Close #2

End Sub


However, the file I get is not the same size as the server reports, nor is it the same...what am I doing wrong?

Binary File Write In VB6
I want to output this data to text and binary files. The binary
file contains the garbage I would expect to see if I try to read
it with a text editor, but below that the output appears as text.
It's been a long time since I've written any VB code. What am I
doing wrong? (The default value of modulus is 255.)


Private Sub cmdStart_Click()
'samples an image at intervals depending on the settings
'of range (number of rows and columns) and stepval (interval
'between pixels) and generates a prnd number by performing
'modular division on the color value of the pixel

Dim nbin As Byte
Dim numbers As String
Dim row As Integer
Dim col As Integer
Dim n As Integer
Dim colcount As Integer
Dim range As Integer
Dim stepval As Integer
Dim modulus As Integer

colcount = 0
numbers = ""
range = Val(txtRange.Text)
stepval = Val(txtStep.Text)
modulus = Val(txtModulus.Text)

'send data to a text file and a binary file
Open "C:windowsdesktopdataotpad.txt" For Output As #1
Open "C:windowsdesktopdata
nd.dat" For Binary Access Write As #2

For row = 100 To range Step stepval
For col = 100 To range Step stepval
n = pboxImage.Point(row, col) Mod modulus
nbin = pboxImage.Point(row, col) Mod modulus
numbers = numbers & Str(pboxImage.Point(row, col)) & vbCrLf
If n > 0 Then
Print #1, n;
Put #2, , nbin
colcount = colcount + 1
If colcount Mod 10 = 0 Then Print #1, vbCrLf
End If
Next col
Next row
Close #1
Close #2

txtNumbers.Text = numbers
End Sub

Binary File Write In VB6
I want to output this data to text and binary files. The binary
file contains the garbage you would expect to see if you try to
read it with a text editor, but below that the output appears as
text as it also appears in the text file. It's been a long time
since I've written any VB code. What am I doing wrong? (The
default value of modulus is 255.)


Private Sub cmdStart_Click()
'samples an image at intervals depending on the settings
'of range (number of rows and columns) and stepval (interval
'between pixels) and generates a prnd number by performing
'modular division on the color value of the pixel

Dim nbin As Byte
Dim numbers As String
Dim row As Integer
Dim col As Integer
Dim n As Integer
Dim colcount As Integer
Dim range As Integer
Dim stepval As Integer
Dim modulus As Integer

lncount = 0
numbers = ""
range = Val(txtRange.Text)
stepval = Val(txtStep.Text)
modulus = Val(txtModulus.Text)

'send data to a text file and a binary file
Open "C:windowsdesktopdata
andom.txt" For Output As #1
Open "C:windowsdesktopdata
nd.dat" For Binary Access Write As #2

For row = 100 To range Step stepval
For col = 100 To range Step stepval
n = pboxImage.Point(row, col) Mod modulus
nbin = pboxImage.Point(row, col) Mod modulus
numbers = numbers & Str(pboxImage.Point(row, col)) & vbCrLf
If n > 0 Then
Print #1, n;
Put #2, , nbin
colcount = colcount + 1
If colcount Mod 10 = 0 Then Print #1, vbCrLf
End If
Next col
Next row
Close #1
Close #2

txtNumbers.Text = numbers
End Sub

How To Write To Binary File
Hi
I have a string that contain a BMP file (Content like: BM......) and i need to create a bmp file and then write all the string content in to it so in the end of the process i will have a valid bmp file that i can view in MSPaint for ex'.

Here is what i try but it don't work (Text1.Text will contain the text BMP):
Dim buffer As String
mImageEx.GetImageBufferData Text1.Text, buffer
Kill "c:MyTest." & Text1.Text

Open "c:MyTest." & Text1.Text For Binary Access Write As #1
For i = 1 To Len(buffer)
Write #1, Mid(buffer, i + 1, 1)
Next i
Close #1


What do i do wrong?
Can any one tell me how to solve this problem?
Thanks

Question About Write Binary File
I want to write one byte to a file, the data is from text box, a HEX number. Why it always write 6 bytes in the file?

Dim b1 as byte
b1 = CLng(Val("&H" & Text1.Text))

Open "c:data1451" For Output As #4
Close #4
DoEvents
ifreefile = FreeFile

Open "c:data1451" For Binary Access Write As ifreefile
Put #ifreefile, , b1
Close ifreefile

b1 is a HEX number, I open a file c:data1451 and "put" the one byte data b1 to the file. It always shows 6 bytes when i check the size of c:data1451 .
Thanks.

How To Write Binary To File (bits)
I experimented a bit with huffman compression and such, and it gives me back a string of 0's & 1's which is good.

Now I would like to save this binary thing back to file, but not as string, but as pure binary (because making the file smaller is the whole point of huffman compression)

How do I do this?

I know "open File for binary as #1" doesn't do what I want... I have no clue...

Can anyone give me a hint?
Reinout,

Binary Write/Read To File
Hi all,

I would simply like to write a couple variable values to a file so that no one can visually read the file...only my program can read it in. I THOUGHT that writing it in binary would be the answer, but I'm having problems. Could someone supply me very simple code that will write a number and string to a file in binary...and also the code to read it back in??? I very much appreciate it!!

At Which Position Does Put Write In A Binary File
Hi,
I'm using the foolowing syntax to write data into a binary file:

Code:
Put DatNr, , CInt(1)



Is there a way the get the exact position at which the next Put statement would be writing (automatically by ommiting the filepostion like I did it in my code)?

Binary File Read/Write Help
I am currently using VB6 with SP5. I am working on a program to allow the user to put in a series of valid keystrokes into individual textboxes. These text boxes are set as an array. They are called txtPg(0) to txtPg(99).
I then have it call a subroutine to store the txtPg(x).text to a mutlidimmensional array defined as keystroke (1,100). Now it stores the information in keystroke (0,x) for that entered by the user.
The next thing it does is then convert the data stored in keystroke(0,x) to its defined hex equivalent and then stores that in keystroke (1,x).

Now what I am trying to accomplish next is take that information that is located in keystroke (1,x) and write it to a binary file. I have been trying to find information on the internet to help since every book I have is vague on working with binary type files.

The other thing I need to do is take the binary data in any given binary file and read that into an array most likely also multidimmensional. I guess I could store that in to one secion of array then convert that to its defined hex values and then convert those hex values to it equivalent keypresses. I need to do this in case the user wants to edit and existing file. I will then take the keypress information and put that into the txtPg(x).text location so that the user can modify as needed. Then of course re-use the subroutine to write back to another file.

I know I am asking a lot but I have been unable so far to find a good example or tutorial to help me understand what is involved with binary file access. If someone can help by either helping me with code and/or giving me sites to go examine I would greatly appreciate it. I guess I need to find some good books or information on binary file manipulation.

Thanks in advance for all your help.
God Bless You All.
DaWolf

Need To Write Binary Integer To File?
Hi,

I need to write out the two-byte (binary) integer value to a binary file using vb6.

To make things clearer, each "record" in the binary file must have the first 2 bytes represent the length of the record. This file will be passed to a Windows PL/1 program which will read it using VARLS file type. I cannot seem to get VB6 to write or to populate a string with the two-byte representation of an integer.

Can anyone help me out please?

Thank you!

Rick

Read And Write Binary File
hello
help me, how to read and write a string of byte into binary file
thanhk you

Write Object To Binary File
Hi !

How can i write an object to a binary file ?

Binary File Read And Write In VB
In Visual Basic 6 I have written a program to read and write to a file. It works fine. Now I have to do the same for binary data since the information I write to the file has end-of-line and return characters. For instance, when I write to the file, the data looks like this:

"3
34"

Because there is a break in the data. In debug mode, the text data has two boxes where the end-of-line and return characters go.

Anyway, does anyone have any example code of binary level reading and writing to and from a file?

Binary File Is Increasing In Size With Every Write
Hi,
I have a code that writes to a binary file and looks somewhat like the following:

Code:
'Data is a byte array

Dim hFile As Integer
hFile = FreeFile

Open FileName For Binary Access Write As #hFile
Put #hFile, ,Data
Close #hFile
After every write it is increasing in size, meaning that it's previous contents are not erased, as with Output mode. When I tried to solve this problem with placing this line of code before the first Open statement,

Code:
Open FileName For Output As #hFile: Close #hFile 'Clear the previous contents
The file started increasing in size by one byte each time written to it.

What can I do to solve this problem?

Read N Write A Class Into Binary File
hello, i got some problems here

i have a class T_icon ,with datamembers :
image as picture
index as integer
x as integer
y as integer

then i declare some object like :
dim icon as T_icon

and i try to save it like this :
nFileNum = FreeFile
Open App.Path & "output.dat" For Binary As nFileNum
Put nFileNum,1,icon
Close nFileNum

when i compile it, some error shown, i dont really remember what the
error says, its something like this :
"cant Get / Put an object references ..... blablabla ...."

what i want to know is how to save a object of class into binary file?
i try with integer or string and it work well, but when i try a class it dont
work. plz help me .....

Binary File Read/Write Issue
Hey all,

I'm having a slight problem with my program writing to a binary file.

First, the code:

--
Public Sub Access_Server()

ServerFile = App.Path & "server.dst"

fFile = FreeFile

'Open the server.wdc file to be read from.
Open ServerFile For Binary Access Read Lock Read Write As #fFile

'Grab IP from file and set it to svrIP variable
Get #fFile, 1, svrIP

'Grab Server Port from file and set it to svrPort variable
Get #fFile, 2, svrPort

'Finished with the file, so we close it
Close #fFile

End Sub
--

This is my reading portion. The writing looks exactly the same, only instead of "Get" I have "Put".

What this is supposed to do is just store a server IP and Port to a file in the program folder. This worked once before, but as soon as I put it in a module, I started having problems with it and now I can't even get it to work when I put it straight on the form. It seems to save the port with no problem, but the IP address is where the issue comes in.

Let's say I have 192.168.0.0 as the IP. My IP in the file and when I read from it turns into 1C|.168.0.0 or something to that effect.

I hope I've included all information in this. If anyone can help, I would be greatly appreciative! I've tinkered around with VB6 for about 6 years off and on at my leisure and this is the first time I've really messed around with I/O in files.

Thanx in advance!

~Derek

EDIT:
I should mention that where I have "1" and "2" (which byte it starts with) I had that cleared once before.

So it would be:
Get #fFile, , svrPort

As soon as I put it in the module, that is where my trouble began. It won't read the IP address at all when that field is cleared, and instead of giving back the port number I specified, it seems to pull a random number out of the air.

How To :- Binary File Open, Write, Copy
I wnted to learn some ways to copy files, read file and write into file in binary files.....my mastering vb6 doesn't help much for binry mode and nor the msdn tooo.(actually i've n't been able to find any proper example for that)....

please help me....

SA. CH. R

Write Text File Binary Append Mode
Hi

I am using following code:


vb Code:
Public Sub PutTextToFile(ByVal sFile As String, ByVal sText As String)    'Writes text to file sFile    'Example usage: Call PutTextToFile("C:Programs.txt", "test")    Dim I As Long    On Error GoTo PutTextToFile_Error     I = FreeFile    Open sFile For Binary Access Write Lock Read Write As #I    Screen.MousePointer = vbHourglass    DoEvents    Put #I, , sText    ExitHere:    On Error GoTo 0 PutTextToFile_Error:    Close #I    Screen.MousePointer = vbDefaultEnd Sub
It overwrites the existing file. Instead, I want to append the new text to an existing file. How can I do that?

Please help

Binary And Normal File Write In One File
I have a small problem, i need to be able to write 2 binary characters, plain text (standard text) and a bitmap image all into one file... the file would look like


the [] is the best i can do so simulate a binary/hex square thingy...


[]Message[][][][]Bitmat Here

The first Binary would be the hex "07" then in plain readable text it needs to say "Message" and then i need to write in hex "00 00 11 80" and then write the bitmap in binary mode again...

if i put a line like

Put #FileNum, , Hex(Len(Message)) & "Message" & Hex(Len(Bitmap)) & Bitmap


it writes it all in binary and all ends up messed up, if i miss the Hex's out it writes it all in normal and corrupts the image so the file ends up like

7message00001180GarbledImage

I guess what i need to know is, is there a command like Hex(), Asc() etc that makes characters hold there Alpha/Normal value ?

Does anyone have any idea how i do this ?

Saving Binary File When New Data Is Shorter Then Old Data?
I am having trouble saving a file with binary access when the current data is short than the old data. How do I remove the extra data from the file before writing my new data? I am currently using the following code:

VB Code:
FF = FreeFileOpen sFilePath For Binary Access Write Lock Read As #FFPut #FF, , sFileClose #FF


I have encountered this problem in the past and have never found a solution. Any ideas?

Solved -- How To Write New Data Into A Txt File And Not Overwrite The Old Data
I am using the FileSystemObject to write data into a .txt file, but I don't want to overwrite the old data when i write the new data.
Does anyone know how to do it?
Thanks!

Claire

Write Data From Text File To A Excel File????
i have a data in text file (file is attached). i want write the data to a excel file.How to write the code???

Write Data From Text File To A Excel File????
i have a data in text file (file is attached). i want write the data to a excel file.How to write the code???

How To Write Data To A Txt File
Hi my name is dimitris
and i have a problem i have designed a questionnair in visual basic and i dont know how i can collect the data that a user enters into a txt or xls or doc file if anyone has an idea....

How Write Data On A File?
Dear Sir,

I want to wirte some data on a file (Hex Data) , I use Open command and Print command to write my data to file but I see some other data in file such as CHR(13)+CHR(10) in eof file or some header in binery mode .
Please help me how I wirte data without any other data in a file

Data To Write File
Hi,

I want to write the data that receive from the serial port to a file with a extension of .dat.

And recieved data will be written into a different filename.

example - 1st groups of data receive will store into file1 and 2nd grp of data receive will store into file2.

Meaning the filename will change whenever there is already an existing filename been used which the code able to change the filename.

Lastly, how can i choose a location which i want the file to be save.
example, C:APPS emp

Meaning user able to select a location for saving the file.

Thanks

Write From Data To A Txt File
This is my second day with Visual Basic.

I just tried to add a menu, and made a menu 'file'.

Caption: Save
Name: mnusave

Is there possible to make a txt file out of a textbox called text10?

Like if this is in Text10: 'hello there'
Is there possible to make that save as object.txt in the folder you got the .exe file in?

Sorry about my english.


- Marius

Write Data To A Xml File
hello,

yet again i am struggling to find visual basic and xml related tutorials and articles, i was hoping someone could tell me how to write to a xml file. To set the sceen i am going to have 2 text boxes, text1 and 2 and a command button, command1, when i fill in these boxes and click the command button i want it to write to the xml file, here is the current xml file:


Code:
<?xml version="1.0" encoding="ISO-8859-1"?>
<First id="1">
<Topic>First XML Document</Topic>
<Message>Not Bad For a First Attempt</Message>
</First>

when the command button is press i want text1 to overwrite the contents of Topic and text2 to do the same for the Message

thanks
lee

To Write Data In A File.
Hi,
I want to write some data in a file form a program after a specific interval. Suppose for 30 seconds, I want to write like
time magnitude
1 1.3
2 1.5
. .
. .
30 1.2

Can u help me to write this code?

Thanks a lot.

How To Write Data In XML File
hi all,

in my application i have create one xml file n i want to write the data in this file using
VB Code:
Set objAccess = New Access.Application


How can i do this ?? in VB 6.0

Data is comming from query ..

i have problem in this code


VB Code:
Dim strDate As StringstrDate = "insert into tempDate values(#" & fromdate & "#,#" & todate & "#)"conOrders.Execute strDateSet rsMapping = New ADODB.RecordsetstrDate = "Select count(*) as total from Can1Z_Orders where Can1Z_Orders.DateToUPS >=  #" & fromdate & " # and Can1Z_Orders.DateToUPS <=  #" & todate & "# and Can1Z_Orders.DetailInd = '" & TypeId & "'"    rsMapping.Open strDate, conOrders, adOpenDynamic, adLockOptimistic    If rsMapping.EOF = False And rsMapping.BOF = False Then        If CInt(rsMapping("total")) > 0 Then                    '#########################################            '## create xls file to write data to it ##            '#########################################                 flg = 0     If modInitialize.getMappingDetails = True Then     currdate = Now     filename = CStr(Format(currdate, "mmddyyhhmmss"))     modprcData.checkFiles (modInitialize.BillingDestFileLocation)     filename = modInitialize.BillingDestFileLocation & "" &      modInitialize.BillingDestFileName & filename & ".xls"     Set objFSys = New FileSystemObject     If objFSys.FileExists(filename) = False Then            objFSys.CreateTextFile (filename)     End If     flg = 1     Set objFSys = Nothing                       '###########################################       '## write the output of query to xls file ##       '###########################################       Set objAccess = New Access.Application       With objAccess             .OpenCurrentDatabase App.Path & "UPSThermalLabels.mdb"             If TypeId = "1Z" Then                    '*****Calling The Query For The 1Z label ********'                    .DoCmd.OutputTo acOutputQuery, "Billing", acFormatXLS,                       filename,   True             ElseIf TypeId = "ZAR" Then                    '*****Calling The Query For The ARS label ********'                    .DoCmd.OutputTo acOutputQuery, "Billing_ARS", acFormatXLS,                     filename, True             End If                     .CloseCurrentDatabase       End WithobjAccess.QuitSet objAccess = Nothing                MsgBox "The orders have been written to " & filename                End If Else   MsgBox "No records Found!!!"End If                 rsMapping.Close    Set rsMapping = Nothing    conOrders.Close    Set conOrders = Nothing



this code is work fine up to the creation of exel(XML) file creation...
i have no of records in my access database if i want to read data in between '11/01/05' to '12/31/05' then it's retrive 2 records which is correct
but if i want to retirve the data in between the date '11/01/05 to '1/30/06' then it does not show me any thing in XML file (File is get Created but No Data In that file) pls tell me what's is wrong in this code...

else tell me how to write the Data in The XML file..
so i can solve this problem

regards,

Need To Write Data Into A PDF File.
Hi,
Please some body help me to write a report or a few lines into a PDF file.

Thanks,
Sam

Reading Data From Binary File
I have a prob in reading data from specified position from a binary file

This is my probs..

I am writing data in a file opening in binary write mode in 5000 and 15000 positions using put statement

Data in 5000 position is "15000"
Data in 15000 position is "Test this"

So now when i tried to read data from that file using get statement it is not giving me the correct data for me , so let me know what is the probs
If any one has code let me know that , it is urgent

Thanks

How To Read Binary Data From A File
i want to read data from *.SD5 file...the data in that file is stored in binary formate...i want to read all the data from that file
in string or text formate.......how to do that............i used the following code...but i get some junk...

Private Sub Command1_Click()

Dim MyString, MyNumber
Open App.Path & "sarsewa2sarangarh.sd5" For Input As #1 ' Open file for input.
Do While Not EOF(1) ' Loop until end of file.
Input #1, MyString, MyNumber ' Read data into two variables.
MsgBox MyString & MyNumber ' Print data to the Immediate window.
Loop
Close #1 ' Close file.

End Sub

SAve Data In Binary File
HI, im trying to save data(hex data) in a Binary file(.BIN).... the problem its that if i save data only with rename .bin thats gives me MORE size than i load to the file....... example: if i save 32,000 bytes(each byte its on hex format) the finall file its 3 or 4 times more bigger thant the data i save....... i need to save for example 1024 bytes of data and have the BIN file of 1024 bytes... whats wrong??????????
HELP PLEASE!!!

Reversing Data In A Binary File
Hello, I'm using the code below to reverse data in a binary file. It takes a chunk of data, reverses the data and writes it to a new file. Then it does the same with the next chunk, etc, etc, until all data has been reversed and written to a new file.

The new file is corrupted, but when the same process of reversing is done with the corrupted file, it becomes the original file again.


I'd like to know if this is the fastest way of doing it or is there a faster way? The smaller the chunk size is, the longer it takes to reverse the data.


Code:
Private Sub Command1_Click()
Dim btBytes() As Byte
Dim i As Long
Dim j As Long
Dim btTemp As Byte
Dim lFilesize As Long
Dim lChunkSize As Long

lChunkSize = 100000

ReDim btBytes(lChunkSize - 1)
Open "C:file1.dat" For Binary As #1
Open "C:file2.dat" For Binary As #2

lFilesize = LOF(1)

Do While lFilesize >= lChunkSize
DoEvents
Get #1, , btBytes
i = LBound(btBytes)
j = UBound(btBytes)
Do While j > i
btTemp = btBytes(i)
btBytes(i) = btBytes(j)
btBytes(j) = btTemp
i = i + 1
j = j - 1
Loop
Seek #2, LOF(2) + 1
Put #2, , btBytes
lFilesize = lFilesize - lChunkSize
Loop


If lFilesize > 1 Then
ReDim btBytes(lFilesize - 1)
Get #1, , btBytes
i = LBound(btBytes)
j = UBound(btBytes)
Do While j > i
btTemp = btBytes(i)
btBytes(i) = btBytes(j)
btBytes(j) = btTemp
i = i + 1
j = j - 1
Loop
Seek #2, LOF(2) + 1
Put #2, , btBytes
End If


Close #1
Close #2


MsgBox "Done"
End Sub

Organizing Data From A Binary File
Hey all, first post.

I am having trouble organizing data once extracted from a binary file.

The file is set up like so:
1) There are is a peice of data at every 2 bytes, and every 2 bytes represents a channel.
2) There are 22 bytes in each second, and thus 11 channels.
3) The first channel and the last two channels need to be disgarded (only channels 2-9 are actual data channels)
4) The data was collected at 1024 samples/sec.

Here is what i've been throwing around for a while now:


Code:
Private Sub cmdTimePlot_Click()
Dim DataPlot() As Integer 'data types
Dim ByteArray() As Integer ' byte = 1 byte storage
Dim ArraytoDisplay() As Integer ' integer = 2 byte storage
Dim total_records As Long ' long = 4 byte storage
Dim starting_record As Integer
Dim ending_record As Integer
Dim selectedChan As Integer
Dim pos As Integer
Dim i As Integer
Dim bytenum As Long
Dim counter As Long
Dim nSamp As Long
Dim nChan As Integer
Dim fSamp As Long
Dim Xdata() As Long
Dim deltaTime As Long

fSamp = 1024
starting_record = CInt(cboFirstSecond.Text)
ending_record = CInt(cboLastSecond.Text)
total_records = ending_record - starting_record + 1
nChan = 8
nSamp = CLng(fSamp * total_records)

Form1.MousePointer = vbHourglass

If (cboChannelPick.Text <> "") Then
selectedChan = CInt(cboChannelPick.Text)
Else
selectedChan = 1
End If

ReDim DataPlot(1 To (CLng(total_records) * fSamp * 11))
ReDim ByteArray(1 To CLng(total_records) * fSamp * 8)
ReDim Xdata(1 To total_records)

counter = 1
Dim countera As Long
Dim fileLength As Long
fileLength = FileLen(tempstrfilename)

Open tempstrfilename For Binary As #1
Get #1, , DataPlot
Close #1

Dim o As Long
Dim bytenum2 As Integer
Dim bytenumcount As Long

bytenumcount = 1

For o = ((starting_record * 11 * fSamp) / 2) To ((ending_record * 11 * fSamp) / 2) Step 11
For bytenum2 = 1 To 8
'skips unwanted first channel and leaves 9-11 out to dry
'gettting a "Script out of range" error below here
ByteArray(bytenumcount) = DataPlot((o * bytenum2) + 1)
bytenumcount = bytenumcount + 1
Next bytenum2
Next o

ReDim ArraytoDisplay(1 To CInt(((bytenumcount) / 8)))

Dim p As Long
Dim q As Integer
Dim SecInc As Long

SecInc = 1

For p = selectedChan To bytenumcount Step 8
ArraytoDisplay(SecInc) = ByteArray(p)
SecInc = SecInc + 1
Next p

With CWGChannelGraph
.PlotY ArraytoDisplay, starting_record, 0.5
End With

Form1.MousePointer = vbDefault
End Sub
I hope you can help me out .

Saving Binary Data To A File
Is there any way to save a variable to a file without having to resort to text?

An example is something like saving a byte array. I want to be able to point to the file as if it were a byte array object. I want to avoid opening as text and parsing the values into a byte array.

Hopefully this makes sense.

Retrieving Data From A Binary File
hi, I'm trying to retreive data from a binary file.

I select and open a database, for which each record contains a binary file. when i select a record, i need to retreive data from the binary file, but it won't work.


Code:
sqlD = "SELECT * FROM RawMotions"
rstDupARS.Open sqlD, dbSpectra

rstDupARS.MoveFirst

Do While Not rstDupARS.EOF
recordCnt = recordCNt + 1
recDPt = recDPt + RS.NumPts
rstDupARS.MoveNext
Loop

where, RS is

Code:
Global RS As RSSTRUCT

Type RSSTRUCT
NumPts As Integer
NumCurves As Integer
damp(1 To MAXDAMPINGS) As Single ' -1 if PVRC
Freq(1 To MAXRSPOINTS) As Single
sa(1 To MAXRSPOINTS, 1 To MAXDAMPINGS) As Single
End Type
Hope this makes sense, thanks.

Insert Data Into A Binary File
Hello, below I have some code that copies a file.
What I need to do is copy the file to certain point (for example 14475000 bytes), write/insert another byte array with data and then write the rest of the original file.



The problem is that I'm reading/writing in larger chunks, because reading/writing a single byte takes too long. Some of the files can be more than 50mb.

How can I read/write up to a certain position and still keep the speed?

Or should I read/write the entire first part of the file (even if it's 50mb), then write the new byte array and then add the rest?


vb Code:
Private Sub Command1_Click()    Dim btBytes() As Byte    Dim ChunkSize As Long    Dim lFilesize As Long    Dim infile As Integer    Dim outfile As Integer     ChunkSize = 32576        ReDim btBytes(ChunkSize - 1) '// Redim Byte array for chunk reading        '// Open Input and Output files    infile = FreeFile    Open "C:originalfile.dat" For Binary Access Read As #infile    outfile = FreeFile    Open "C:
ewfile.dat" For Binary Access Write As #outfile         lFilesize = LOF(infile) '// Get size of Input file for looping through the file         '// Loop through the file        Do While lFilesize > 0            DoEvents                        Get #infile, , btBytes '// Get a chunk of data                    Put #outfile, , btBytes '// Write the data chunk to the new file            lFilesize = lFilesize - ChunkSize '// Decrease size                    If lFilesize <= ChunkSize And lFilesize >= 0 Then '// Last chunk                ReDim btBytes(lFilesize - 1)            End If        Loop            Close #infile    Close #outfile        MsgBox "Done"End Sub

Updating Data In Binary File
hello everyone

i am making a quiz in vb wherein i am reading questions from a binary file.also i am writing the question no and the option selected by the user in a seperate binary file.for eg Q1,4,Q2,5 now if the user changes the answer of q2 to 3 then i want that the file should be updated means that now the file should have Q1 4 and Q2 3.how do i do this.plz give me the code for this

parth

Copyright © 2005-08 www.BigResource.com, All rights reserved