Read A Binary File And Make Changes
Hi,
I'm new in VB.... I need to read a binary file and then make changes to the file. How?
The changes are to find specific characters and delete or remove those characters. Then I need to add characters at the beginning of the file and at the end of the file.
After all those changes, how do I save this file?
Thanks!!!
View Complete Forum Thread with Replies
See Related Forum Messages: Follow the Links Below to View Complete Thread
Read Binary File
i have i hope a very simple question
i have a binary file (mpeg file) that i need to get a hex figure from at a specific address.
ie address is &H82B
once at this point i need to read the byte and return the value (will be 3 or 4)
inputifo = "blah blah"
ff = FreeFile
Open inputifo For Binary As #ff
s = Input(LOF(ff), ff)
Dim a As Byte
but stuck here
thabks
Binary File Read
hi,
i want to read a binary file, the structure of which is defiled in "C".
the "C" structure defenition of the file is the following.....
History file is a binary file with structure as below. any one can help me with the code/tips to read this file in VB 6.0
thanks
sjp
oldest data set; oldest-1 data set;... newest data set; header; eof
1.2 Data set description
Ever data set header is defined in following C style structure
/*-------------------------------------*/
typedef struct {
int number ; //current number of data set
time_t time ; //time stamp of data set(calendar
time, count of seconds until 0:0:01.1.1900)
float pressure ; //absolute pressure in hPa
float wind_speed ; //wind_speed in m/s
enum DIRECTION wind_dir ; //wind direction
float rain ; //rain counter in mm
float in_temp ; //indoor temperature in °C
float out_temp ; //outdoor temperature in °C
unsigned short in_hum ; //indoor humidity in %
unsigned short out_hum ; //outdoor humidity in %
}HISTORY_DATA_SET;//end of struct HISTORY_DATA_SET;
/*-------------------------------------*/
enum DIRECTION { N,NNE,NE,ENE,E,ESE,SE,SSE,S,SSW,SW,WSW,W,WNW,NW,NNW, ERR,};
/*-------------------------------------*/
typedef unsigned int time_t;
/*-------------------------------------*/
1.3 Header description
The header is defined in follwing structure (C style)
/*-------------------------------------*/
typedef struct {
unsigned int magic ; //number for
header authentification equal to0x21436587in current version
//rain values
float rain_offset ; // rain offset (
substract to get the correct value)
float last_rain_value ; // for internal
use - last rain value used to detect rain counter overflow
time_t rain_reset_time ; // time of last
rain reset
//DATA information
int data_count_in_file ; //count of data
sets in buffer
time_t time_of_first_saved_set ; //time of first
saved data set (calendar=seriell time)
time_t time_of_last_saved_set ; //time of last
saved data set (calendar=seriell time)
}FILE_HISTORY_HEADER;
/*-------------------------------------*/
1.4 History actualisation
The history file will be on run time of the „heavy weather“ cyclic actualised. First will be append the new data
set on the end of file. The old header will be overwritten. Then the new header will be append on the end of file
.
Read Binary File
Hi!
Someone Can tell me how to know if a string ex.: "TAG2" is in a binary file and how to know is position?
Thanks!
JP III
How To Read From Binary File?
Hi
I have a binary file that i need to read the first 5 values in it.
To do this i tried the Open & Input but i guess i doing something wrong cuz it didn't read it as i need.
I have a code that do this in VC but i need it to be converted in to VB
can any one help me?
Here is the code in vc:
Code:
WORD pVersion[4];
file.Read(pVersion, sizeof(pVersion));
What VB have to used as WORD data type?
Thanks
Binary File Read Query
I'm a fairly new to VB 6 and have just been tasked with reading in a binary file. I've done text file before but am lost on binary stuff....
I'm sure that this is an easy but I'm having real difficulties.
Background: the file I'm reading is 897Kb in size. I want to read that in and pull out parts of the file I'm interested in (there is a number of records stored in the file). I'm interested in stuff at byte position 1..1, 2..4 & 5..6 for each record.
I have read the tutorial but have had no luck to date.
Heres my code so far:
Private Sub loadData(filename As String)
'cater for fact cancel was chosen
If filename = "" Then Exit Sub
Dim fFile As Long
Dim bBuf() As Byte
fFile = FreeFile
Dim myarray
Open filename For Binary As #fFile
If LOF(hFile) Then
ReDim myarray(LOF(fFile))
Get #fFile, , myarray
End If
Close #fFile
end sub
As soon as my code trys to executte the Get #fFile, , myarray I get a runtime eoor '458' - variable uses an automation type not supported in Visual Basic.
Any clues whats going on here please.
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
How To Read Large Binary File
I use the following code to read a file as binary:
ReDim buffer(FileLen(filepath) - 1)
Open filepath For Binary As 1
Get #1, 1, buffer
Close #1
The code works fine is the file size is small. If the file size is large, error happened.
How can i read large file?
Read A Binary File In VBSCript...Please Help
I have to read a binary file ,
some of the text in it , i can read, but some of it I just can filter out of the text because after the text there are unknown characters like rectangles....
Anybody has sample code to read from a Binary file, in VBScript?
It would be great,
please help me out
Thanx
Qman
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!!
Read A Binary File And Parse
Hi!
I've already tried reading a text file and parse it character by character using "Open....for Input as #1" command, but how about reading binary files and parse it byte by byte? Binary files are not readable and i'm trying to locate a special character like '*' or '|' (pipe in Unix)...
please help on this... I need a sample code.
Thanks in advance and more power to all.
How To Read An Image File As Binary
NOTE: This question came out as part of a discussion on a different issue, I thought it is better to post it on this section to reach a solution.
Here is a link to a proposed code but did not work.
My question is how to read an image file as binary into memory and then bitblit the image to a form. What API functions should be used?
Read VB6 Variant From A Binary File With .net
I need read from my .net application a binary file written with VB6. I can get longs and string written with VB6 with .net BinaryReader class ut how can I read vb6 variants? Do you know how variants are save in binarry file? how much bytes do they take?
Thanks in advance
Fast Way To Read End Of Binary File
Hi, does anybody know a fast way to read the last 3000 bytes of a binary file?
I know I can use the Seek function and specify from which byte it should start reading, but the size of every file is different (between 500kb and 2GB), so reading from the same byte position every time won't work.
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
Binary File Read Loop
I am reading data from a .dat file at certain points in the file:
Code:
Private Sub GETFROMFILE(FILENAME As String)
Dim STRARR(2) As String
Dim FileLength As Long
Dim ByteArray(99072) As Byte
Open FILENAME For Binary As #1
FileLength = LOF(1)
Get 1, , ByteArray
Close #1
Dim Temp As String
For k = 0 To 2
If (ByteArray(k) < 127) And (ByteArray(k) > 32) Then
Temp = Temp & Chr((ByteArray(k)))
Else
Temp = Temp
End If
Next
Dim Temp2 As String
For k = 13 To 58
If (ByteArray(k) < 127) And (ByteArray(k) >= 32) Then
Temp2 = Temp2 & Chr((ByteArray(k)))
Else
Temp2 = Temp2
End If
Next
'Spacing - 3 then space 11, 45 then space 683
Dim Temp3 As String
For k = 741 To 744
If (ByteArray(k) < 127) And (ByteArray(k) > 32) Then
Temp3 = Temp3 & Chr((ByteArray(k)))
Else
Temp3 = Temp3
End If
Next
Dim Temp4 As String
For k = 755 To 800
If (ByteArray(k) < 127) And (ByteArray(k) >= 32) And Not (ByteArray(k) = 42) Then
Temp4 = Temp4 & Chr((ByteArray(k)))
Else
Temp4 = Temp4
End If
Next
End Sub
The data is spaced as follows:
3 chars then space of 11 chars , 45 chars then space of 683 chars
How can I loop through the data getting these values?
Read Binary File (RESOLVED)
I am using the code below to read a .dat file.
Code:
Private Sub GETFROMFILE(FILENAME As String)
Dim STRARR(2) As String
Dim FileLength As Long
Dim ByteArray(99072) As Byte
Open FILENAME For Binary As #1
FileLength = LOF(1)
Get 1, , ByteArray
Close #1
Dim Temp As String
For k = 1 To 3
If (ByteArray(k) < 127) And (ByteArray(k) > 32) Then
Temp = Temp & Chr((ByteArray(k)))
Else
Temp = Temp
End If
Next
Dim Temp2 As String
For k = 15 To 28
If (ByteArray(k) < 127) And (ByteArray(k) > 32) Then
Temp2 = Temp2 & Chr((ByteArray(k)))
Else
Temp2 = Temp2
End If
Next
Text1.Text = Temp
Text2.Text = Temp2
End Sub
This code returns the information from the file, but removes any spaces in the text. Any ideas as to why?
Thanks
How To Read A Binary File, Without Having VB Converting The Value
I got a binary file, which stores data. This data is stored Hex, at least when I look at it with a HEXeditor.
Well, I try to read the values in the file. I use the function :
Get #intFileNumber, position, intValue
(where intValue As Integer)
Well, VB takes these numbers and converts them into decimal numbers. I think it does that, because I use intValue as Integer.
Well, I think that it converts it into decimal numbers. I check it by using the function
intMsg = MsgBox(intValue)
For my needs, VB is not supposed to do this, because I do need the binary numbers, and analyse them bit by bit. My problem here is, that VB takes the HEX number “F43A” and converts it to –3014 . When I take this decimal number and try to convert it to a binary number I just get ****. (I get a number, but not the one I want.) I am supposed to get the binary number 1111 0100 0011 1010 .
That is exactly the value I have to work with, but I do not know how to get there.
(This is not a Big Endian vs Little Endian problem, I took care of that. By the way, the number is stored as 3A F4, in little Endian)
I did try to read the value as a string and as Variant, but I just got errors.
Can anybody help me.
I tried to be as specific as possible, if something is not clear, just write me.
Dll File Corrupted Using Binary Read
Why is it that after I did an open dll for binary read and closed it the file was no longer usable? I didn't think it actually changed anything when you did that.
This is what I used:
VB Code:
Myprog = "S:Tech SupportCurrent Appsgif89.dll"Open Myprog For Binary Access Read As #1ReDim Dll_File(FileLen(Myprog))Get #1, , Dll_FileClose #1
Quick Read Of Binary File
If i use the standard Windows search box and do a Contents search of a file looking for a word, it comes back with the results really quick....< 1 second....but when i try and simulate it using vb code its really slow. Im not sure if its just because im running it in the IDE (it may be faster once compiled). All im doing is opening the file for binary access and then doing an INSTR for the word im looking for, if not found get next line til EOF. Is there a faster method than this please?
[NEWBIE] How To Read In A Binary File
Hi Folks.
I have the following structure (In 'c' programming code).
Code:
struct player_index_element {
char name[20];
long id; // Sizeof == 4
};
that data is saved to a BINARY FILE (on linux).
The entire size of each STRUCT is 24.
how do i read this in, in VB?
i just can't figure out how to do ? i tried using BINARY to read, and RANDOM and failed..
could some code snippets please be suggested?
Thank you kindly!
-Pure Kr0me-
Read A Binary File And Parse
Hi!
I've already tried reading a text file and parse it character by character using "Open....for Input as #1" command, but how about reading binary files and parse it byte by byte? Binary files are not readable and i'm trying to locate a special character like '*' or '|' (pipe in Unix)...
please help on this... I need a sample code.
Thanks in advance and more power to all.
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?
How To Read Binary Data From INI File
Hi All,
Can anyboady tell me how to read binary data from INI file ?
As in my ini file I am storing a string which may have all possible ascii value (including '/n'..'/r'...and all other except 0 i.e. null ).
When I read it using GetPrivateProfileString then it's not able to read all these special characters ...
Thanks,
-Yogendrasinh
How To Read Binary Data From A 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
Able To Read My Binary File In Notepad?
I've been experimenting with binary files and noticed that the file I created in "binary" mode, is readable in notepad? I thought that this mode put every character in terms of a "0" or "1"? Or maybe I'm doing something wrong..
I created a UDT... myRecord
...
' add some strings to myRecord
...
Open myfile for binary as #1
put #1,, myRecord
close #1
....
(I'm trying to protect sensitive data. Next step is encryption.)
any help is appreciated!
Kenny
Open For Binary A READ-ONLY File
Accessing a file in a shared folder somewhere in the local network. This folder has Read-Only rights to the other computers.
Open "\computerXsharenameXmyfile.bin" For Binary Access Read As #1
With "access read" or without it, an error produced saying "path/file access error".
I am changing the Read-Only status of that folder in "computerX" to "full read-write access" and the above command works excellent.
This is absolute nuts cause the "access read" has the meaning the we are trying to open a file in binary mode ONLY FOR READING, and still is not working...
Any idea about this buggy behavior...
Picture File Problem / Binary File Read
Could someone help me with this code?
[code]
SavePicture picTemp.Image, App.Path & " mpout.bmp"
DoEvents
Open App.Path & " mpout.bmp" For Binary Access Read As #7
Do While Not EOF(7)
Get #7, , sFileDataTemp
sFileDataOut = sFileDataOut & sFileDataTemp
Loop
lFileLen = Len(sFileDataOut)
Close #7
[code]
What's happening is, the "Get #7, , sFileDataTemp" line is not returning any data, when I step through my code, it show's sFileDataTemp = "". I've created a temp program that does just the above, and it seems to work fine. All the variables are Dim'd as local strings, except for lFileLen which is a local Long.
I've also verified that the save portion is correct, it generates a bitmap that I can open with any editor just fine.
Thanks
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.
Error On Binary File Read? FIXED
I have a very simple program:
VB Code:
Private Sub Command1_Click() Open "c: empmy.txt" For Binary Access Read As #1 sDATA = Space$(LOF(1)) Get #1, , sDATA MsgBox sDATAEnd Sub
The file exists OK.
LOF(1) shows a length of 50.
But on the GET line, I receive an error of:
" Run time error 458
Variable uses an automation type not supported in Visual Basic "
Any ideas why?
URGENT: How Do You Read In A Binary Data File?
How do you read in a binary data file and save it into an array of records?
I have the basic code for opening a file for input
open "test.dat" for binary As #1
get #1, , EmpDB
get #1, , Current
get #1, , Counter
close #1
and
open "test.dat" for binary As #1
put #1, , EmpDB
put #1, , Current
put #1, , Counter
close #1
but every time I access it, the data that I saved is not there!
any help would be apprciated it!
Can I Read Binary File Created By C++ Application?
The file consists of header and a number of structs.
Something like following:
//
int Version;
int LastData;
struct MMouse
{
unsigned long uMID;
BOOL bDead;
int nWeight;
int nHeight;
char szName[MAX_NAME_LEN];
char sxPhone[MAX_PHONE_LEN];
} MyMouse[];
So, can I read this file from within VB code.
How To Make Binary File Smaller
Hi
I'm writing parameters gathered through a function to a txt file when certain occurances happen. I prepend one parameter to uniquly identify the line being writen and then I close it (I have to close it). My problem is it seems like every time I open and close it I get a bunch of white space in the text instead of just appending to where it left off. This appears to inflate the file to 5 times the size of what it should be.
I'm attaching the output but the source code is on a different machine right now.
I don't want to use 3rd party compression at all I just want it small from the begginning. Any Help?
Thanks
JoeyO
Read Image From A Binary File Of Data And Images?
I am ensnarled in a requirement for a VB6 application that will read (and write) a binary file that contains some data and an image.
I can handle the data using get and put commands but I don't know how to handle the image.
In VB.NET I could use a file stream to load the data into a memory stream and use the Image FromStream method to load the image from the memory stream as shown in the extract below:
Dim tS As System.IO.Stream = File.Open(fileName, FileMode.Open, FileAccess.Read)
Dim tsIn As New BinaryReader(tS)
Dim continue As Boolean = True
If continue Then
Dim ms As New MemoryStream
ms = New MemoryStream(tS.Length)
ImageArrayByte = ms.GetBuffer()
Dim CurrentPosition As Long = tS.Seek(0, SeekOrigin.Current)
tsIn.Read(ImageArrayByte, 0, tS.Length - CurrentPosition)
ms.Write(ImageArrayByte, 0, ImageArrayByte.Length)
Dim tempBmp As Image = Image.FromStream(ms)
The only relevant method I found in VB6, however, is something like
Picture1.Picture = LoadPicture("file name")
that expects the file to only contain an image.
Is there a way for VB6 to load an image from a specified location in a binary file or must I delve into GDI+ or Windows API? (If so, are there any tutorials or examples for those APIs?)
Thanks,
Read Delphi Structured Packed Binary File
I have a binary file I need to open in VB6, get the values and output to a text file.
The file is a binary file of variant records consisting of the following Pascal record structure. Each variable is defined following the record structure. Note that in Delphi, these would be packed records and that integers would be defined as SmallInt.
Code:
type jrec = record {journal file entry}
case char of
'E':(refnum: integer; {transaction entry-reference
number 32k max}
amount: real);
'T':(trmsh : byte; {term/shift share byte, term is
low half}
tstyp : timestamp; {ts type- must be $80 to $ff
(negative refnum’s)a}
timep : integer; {minutes from midnight} {4 extra
bits?}
empl : integer; {0..32K empl num, negative if
password mode}
param : integer); {used for other data, such as
trans number}
'L':(LPstCd: byte; {128+state code for license plate
number}
dummy : timestamp; {use tstyp here instead}
lpnum : real); {compressed 8 byte license plate
number}
'P':(LTLoc : byte; {Prev transaction location code
(from table)}
dummy2: byte; {tstyp (THIS TYPE PROVIDES FOR
TRANSACTION LINKING}
LTDate: integer; {last transaction date}
LTRec : integer); {last transaction record pointer}
'O':(trnum : integer; {4 bits for $A, 10 for transnum, 2
for date hi}
dttime: integer; {5 bits for date low, 11 for time}
opt1st: integer; {first 16 bits of controller
options}
opt2nd: integer); {second 16 bits of controller
options}
end; {jrec}
Read, Process && Save Each Line Of A Binary File
Hello I have a file with 10 lines in it.
I want it cut off at 71 characters, because this file is being processed by my FTP server for NEW DIRECTORIES display.
I'm not very good at VB, and what I want to do is this:
Open File
Read each line into a string
tempstring = Left(string,71)
Update line
Next line until EOF
Close File
I tried some different approaches but I'm no hero in file handlers etc.
Any help would be greatly appreciated
Optimization Question. Read Large Binary File -Best Way.
I have a two part question. Using VB6. I have Binary Files anywhere from 20-60 MB in size.
Speed wise....
Is it better to read the file completely into a buffer first and then loop through each byte? - OR -
Or is it faster to create a structure and use GET for each binary data record I wish to read and then parse into an array?
Also, if I do read every thing into a buffer and as I loop through it, what is the best way (Fastest) to convert 4 bytes (deep in the buffer) to a LONG type? Thanks for any advice!
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.
Open Dll File For Binary Read And Store As Resource **RESOLVED**
I'm trying to open a dll file as binary read to store in the database as a resource.. I'm a little new at opening files for binary read but this is what I'm trying to do:
VB Code:
Dim dllfileOpen pathtomyfile For Binary As #1Get #1, , dllfileClose #1
But I get this error on Get #1.
Run-time 458
Variable uses an Automation type not supported in Visual Basic
What am I doing wrong?
Writing Text Data To A Binary File (and Read It Back)
Hey all.
I 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 the binary 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.
VB6: How To Read Data From Binary File In IEEE Floating Point, Little-Endian Format?
I have a proprietary binary file here that contains a variable called 'Hydroxyl #', seven sample titles (2, 5, 9, 12, 20, 23, 31 - these titles could just as easily be text, so they are probably stored as strings), and the associated float values for the variable (44.94, 46.17, 51.93, 54.08, 61.62, 63.75, 84.77). I have attached the zipped data file in 'Polyvl.zip'.
Below, I have also pasted a Matlab script that a long-since departed member of our company wrote to read the file. The script uses the 'fopen' command with the 'ieee-le' option (IEEE Float-Point, Little-Endian, bits not explicity specified).
My question is, how do I properly read (and also, display) this data properly in Visual Basic 6? I am currently using the 'Open ... For Binary Access Read ...' statement and the 'Input' statement to read the data into a Variant type variable. I am able to grab some of the data (Hydroxl #), but the rest looks like garbage.
Contact me at DSanborn3@hotmail, or DSanborn3 (at AIM, MSN, Yahoo) with additional questions or comments. TIA!
Regards,
Daniel
//-----Begin Matlab Script (read_da.m)---------------
function [a,spl_name]=read_da(fn);
% READ_DA -- read NIR NSAS data files.
%
% [a,spl_name]=read_da('filename');
% or
% [a,spl_name]=read_da;
%
% Will not work for full Vis/NIR range.
% Works for spectra transferred from pc to rs/6000 via binary ftp.
%
% See read_fda for reading full Vis/NIR range.
if nargin==0,
[fn,pt]=uigetfile('*.da','Select NSAS *.da file');
fn = fullfile(pt,fn);
end
inp=fopen(fn,'r','ieee-le');
nspec=0;
k=fread(inp,128,'char');
fseek(inp,2944,-1);
%
% loop for reading sample names
%
while ~feof(inp)
nspec=nspec+1;
da=k(65)+k(66)*256;
mo=k(67)+k(68)*256;
yr=k(69)+k(70)*256;
hr=k(71)+k(72)*256;
mi=k(73)+k(74)*256;
se=k(75)+k(76)*256;
spl_name(nspec,1:30)=[setstr(k(5:14))' sprintf(' %2g:%2g:%2g %2g-%2g-%4g',hr,mi,se,mo,da,yr)];
k=fread(inp,128,'char');
fseek(inp,(nspec+1)*2944,-1);
end;
frewind(inp);
a=zeros(nspec,700);
for i=1:nspec
k=fread(inp,2944./4,'float');
a(i,=k(33:732)';
end;
fclose(inp);
//-----End Matlab Script (read_da.m)-----------------
Make File Read Only
Does anyone have a sub that you can pass a file path which makes the file read-only?
Make File Read Only
I'm currently making an install script for a few files and I needed them set to read only. Is there a way to set this attribute actually in VB itself without manually setting it to read only in the properties menu?
Cheers guys.
How Do I Save A XLS File And Make It READ ONLY To Users ?
I have the following code :
VB Code:
' Save workbook in current format ActiveWorkbook.Save ' Save workbook in HTML format ActiveWorkbook.SaveAs Filename:="I:COMMUNICATIONSwebranch_list.htm", _ FileFormat:=xlHtml, ReadOnlyRecommended:=True, CreateBackup:=False
I want to be able to save the .HTM version so that if anyone opens it it will be read-only.
Any ideas how ? Changing the property manually on the file is fine, but when this script runs and creates a new version it reverts back !
|