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




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.




View Complete Forum Thread with Replies

See Related Forum Messages: Follow the Links Below to View Complete Thread
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.

Writing Binary Data To A File.
I want to write mixed data to a file, such as:

start data
string
integer
integer
bitmap data
date
integer
end data

I can get bitmap data into memory with loadpicture, but the function just seems to return a reference.

Alternatively it would be nice to be able to stream an entire object (ie its properties by value) to a file and to stream it back again.

Hope some-one can help. Many thanks.

Andrew

Back With Another Stupid Question.. Writing Characters To Data File
hey guys, im back again with another question...
ok, heres the deal. i have a loop that gets a character from another part of my program(it is a different character each time) and writes that character to a data file. the problem is, that it writes each character on a new line. this doesnt have much effect on the functionality of my program, but for ease of reading, i would like to have the data file more orderly when i go to read it.

here is what i had

Open "output.txt" For Append As #1
Write #1, letter(i)
Close #1

but now, i just have it so each character is added to a string and when the string reaches a length of 30 characters it writes the whole string to file

or another idea i have.. is it possible to start adding characters to a string,
and if there is a gap of more than 5 seconds in between the addition of a character to the string then write the string to a file

maybe i am thinking too much, theres probably an easier way that im not seeing. sorry if this seems over-complicated i explained it best as i can...
thanks again =)

Writing Binary Data To File (Excel)
Hi,
I have problem writing a binary Excel file.

I receive byte array from an xml service, write the bytes to a file named like *.xls, but Excel can't open it.
Both VB I/O and API calls give the same result.

Have you had similar problems? Is there anything to care when writing binary content? Especially for Excel?

Any comment can help!

Best regards,
Frederic

Reading Binary Data From A File And Writing It
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?

Reading/Writing Binary Data To A File
Hi all,

I want to write an application which will accept some text data from theuser in a text box and store it in a file in binary format, so that onlymy application is able to open and read it later.

How should I do it?

Regards,
MRL

Writing Binary Data(image) To A File
from my vb appln i try to copy the image from the clipboard and want to store it in a file. to save image in a file, what object i need to use?

Reading And Writing Binary Data With A File.
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 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 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

Read Binary Text File
hello
how can i read binary text file (unicode) and display it in a string?

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

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!

Help With Read And Writing To Text File
Hi. I have a newbie question,

I have a text file that i want to read and rewrite to a new file. Im using DTPicker to find the string with the date that im looking for and im puting that string into an array.

The problem is though when i rewrite the results to a new file it keeps writing the result i found and duplicates it by how many total orig line the file has.

here is a copy of the file im reading:

Sonji,5/14/2006,8:37:01 PM,Living Room,Yes
Mike,5/15/2006,8:37:01 PM,Living Room,Yes
Al,5/14/2006,8:37:01 PM,Living Room,Yes

when i seach for a date a rewrite it heres what i get ex: 5/14/06:


Sonji,5/14/2006,8:37:01 PM,Living Room,Yes
Al,5/14/2006,8:37:01 PM,Living Room,Yes
Al,5/14/2006,8:37:01 PM,Living Room,Yes

I am using a loop with the array.

any help would be greatful, thanks.

Help Read And Writing To Text File
I have a web browser control that has a listbox. This listbox has numbers listed in it. When I hit "Go", it goes down the list (one every second) and does some code.

Here's my question: How do I get the numbers written to and read from a text file?

Example:

Listbox has:
1
2
3
4
5

When I hit "Go", when it gets to 1, it'll save "1" in a text file, then when it gets to 2, it'll save "2" in a text file and so on.

Then, if I load this into the text box:

5
6
7

It'll read from the text that "5" is already listed and it will skip the code and move on to 6 and save "6" into a text file, then go to 7 and save "7" into the text file.

So, the final text file will look like this:
1
2
3
4
5
6
7

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,

How To Read Binary File And Export To Text File ??
how to read binary file and export to text file ??
thanks very much !

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)-----------------

Convert Text To Binary And Back Again
I have a couple of apps, read for selling, its just i new to incorporate a serial into them. Alot of programs take the namer of the person and genreatoe a personal serial, so, i was going to make a serial generator so i could create the serials for the customers, its just a little app that asks for a name and will convert it through a clouple of math equations, the problem is, i need to conver the name to binary, to begin my "Quest" , can anybody tell me how to convert text to binary. And then , binary to text. I couldn't finad anything on the forums so i decided to post a q.



Edited by - computer01 on 11/3/2003 3:01:25 PM

Writing Back Into A Grid From Text
I saved the contents of a Grid into a database field seperated by Tabs CHR(9) and Returns CHR(13) for the columns and rows.

Now, I'm wanting to read that text back into the Grid. I presume this is possible? Any ideas on how I would do this?

Writing Data To Text File
Hi all,
I want to write data from the sql data base table into a text file through Visual Basic application. Since there could be millions of records fetched I would like to avoid the recordset object or connection object for writing it to the text file. Is there any way to do this.

Thanks

Writing Data In A Datagrid Back Out To Access In VB6
Hello everyone.

I have a small database with less than 1000 records composed of 6 fields. I am able to display the entire database (with scrolling) in a datagrid in VB6. I am also able to modify any of the fields within the datagrid. My question is:

Is there a way to write the entire Datagrid back into the Access Database as a whole?

Any help with this would be greatly appreciated.

Help With Writing To Simple Data Text File
Hello all, first of all I'd like to say that I'm very new to visual basic, we just started working on it at school, and we have to make a project but I can't seem to get it to work. I tried searching the forum for answer to my question but without success.

Here it is:

I'm trying to make a simple kind of phonebook, using 2 forms: one for reading from a text based datafile, and one for writing to it.
The forms look like this, 4 textboxes, (first name, last name, phone number, adress), and a commandbutton to set it in motion.

The datafile is quite simple. A text file made with notepad, looking kind of like this..

2
John, Johnson, 555-4444, Johnstreet 6
Jack, Jackson, 666-5555, Jackstreet 9

the 2 would be the number of records, and the comma's seperate the different data. Now, for Reading the data from the file and displaying it in the proper textboxes, I have this code:

Private Sub Command1_Click()
Dim number As Integer
Dim n As Integer
Dim name(1000000#) As String
Dim phonenr(1000000#) As String
Dim lastname(1000000#) As String
Dim bdate(1000000#) As String
'1000000# is the maximum number of records that can be in the file

Open "C:file.aaa" For Input As #1
'file.aaa would be the textfile
Input #1, number

For n = 1 To number
Input #1, name(n), lastname(n), bdate(n), phonenr(n)
Next n

Close #1

'now display in proper textboxes
For n = 1 To number
If name(n) = Text1 Then
Text2 = lastname(n)
Text3 = bdate(n)
Text4 = phonenr(n)
End If

If lastname(n) = Text2 Then
Text1 = name(n)
Text3 = bdate(n)
Text4 = phonenr(n)
End If

If bdate(n) = Text3 Then
Text1 = name(n)
Text2 = lastname(n)
Text4 = phonenr(n)
End If

If phonenr(n) = Text4 Then
Text1 = name(n)
Text2 = lastname(n)
Text3 = bdate(n)
End If

Next n

End Sub
-----------
(end of code)

This works fine, now the problem is, how can I make it write the strings the user types in the 4 textboxes to the bottom of the file and change the number of records that it holds? I tried to change the code using Output and Write instead of input but I seem to be doing something wrong.. Thank you for any help you can give me.

Writing Text File Data To An Array
I have a tab-delimited text file with each row having 20 "fields" (seperated by the aforementioned tab). The number of rows in the file varies. I want every data element to be written to an array that is dimensioned
UploadArray(20, j) where j represents the row in the text file. How can I do this?

Thanks~

Writing Bitmap Data To A Text File.
Hey all, this is in regard to the following post:

http://www.xtremevbtalk.com/showthread.php?t=258418

What I would like to accomplish is to take a bitmap image and write its data to a text file, which can then be read in by the program at another time and set to a StdPicture or IPicture object. I'm assuming that I'd want to use a byte array to store the info and then just read/write the raw data from that array but I'd just like some input on the correct procedure to accomplish this.

I know how this is done in C++, so I'm not a complete dunderhead . I'm just wondering about the correct way using VB syntax.

Thanks much!

Writing Text File From Winsock Data?
Hey again,

i have a server, and a client which connects to the server, but I am wondering if its possible to take the info that is sent to the server from the client (say, text1.text and text2.text) and create a text file, on server side, right away once the data has been recieved?

Writing Data To A Text File From Different Modules
I have the following code in my main form:


VB Code:
debuglog = config.strDebugPath & "debug.txt"    Open debuglog For Output As #2    Print #2, "Program Initialized"    Print #2, ""


Now, I need to write to the debug log from multiple code modules but when it goes to write to it it errors out with "bad file name". Is there any way this can be easily done without opening and closing the file multiple times?

Thanks,

Jim

Writing / Retrieve Data From Text File
hi i'm using the code below to save data from txtNames and txtPass to blocked.txt file. how would I retrieve the password for a user.

Here's how it would work I'll have a txtSetUser.text = "Matt" and txtSetPass.text = "" then when press the command button to retrieve password the code would automatically take the text value from txtSetUser "Matt" and scan through the blocked.txt file for the matching password then input the password to txtSetPass.text


Code:
Open App.Path & "blocked.txt" For Append As #1
Print #1, txtUser(0).Text & ":" & txtPass(0).Text
Close #1


if there is a simlar way of doing this let me know but right now i'm saving the passwords in a User1:Pass1 format in the text file

Writing Data From File To Text Fields
I have tried to implement the statements and it works OK exept when clicking command button 2 without clicking command button 1. How can I write the information from the txt-file to the two text-boxes?
Best regards Hans Peter



Code:
Dim var1, var2 As String
Private Sub Command1_Click()
var1 = Text1.Text
var2 = Text2.Text
Open "c: est.txt" For Output As #1
Print #1, var1
Print #1, var2
Close #1

End Sub

Private Sub Command2_Click()
Dim strLine As String
Open "c: est.txt" For Input As #1
Do Until EOF(1)
DoEvents
Line Input #1, strLine
List1.AddItem strLine
Loop
Close #1
Text2.Text = var1
Text1.Text = var2
End Sub

Writing To Text File W/out Re-wrtiing Over Previous Data
I have this program that makes a log of input text from the user..

But I would like so that when the user saves the log, it does not overwrite previous logs from previous saves..

Anyone wanna help me out?

I just use the Open for Output functions.

VB6 - WRITING TO A TEXT FILE -Date/Time Data
I am trying to write data to a text file by way of a query. The data is coming from joined Access 2000 tables. Everything writes to the text file properly except the 2 fields that are of DATE/TIME data type. They appear with # on either end. ie: #2003-06-15#.
It needs to appear mm/dd/yyyy without the #s. Please help!
Here is output sample and a code sample.

OUTPUT:

"10129498","C","PRUITT ","MARK ","12487 GLENGATE ","3142051540","M",#2003-06-15#,#2039-12-31#,"24.88","15"

CODE:

Open strFileName For Output As #1
Do Until strCurrent.EOF
strCurrent("account"), strCurrent("status"), strCurrent("lname"), strCurrent("fname"), strCurrent("addr"), strCurrent("hphone"), strCurrent("sex"), strCurrent("beg"), strCurrent("exp"), strCurrent("pay"), strCurrent("due"), strCurrent("eftrt"), strCurrent("accountnum"), strCurrent("ccexp"), strCurrent("email")
strCurrent.MoveNext
Loop
Close #1

QUERY:

"SELECT e.client_no as account, e.acct_type as status, e.last_name as lname, e.first_name as fname, c.address as addr, c.city, c.state, c.zip, (c.[hphoneac] & c.[hphone]) as hphone, c.wphone, c.gender as sex, e.start_date as beg, e.end_date as exp, e.monthly_fee as pay, e.billing_day as due, e.bank_aba as eftrt, e.acct_no as accountnum, e.acct_exp as ccexp, c.userd4 as ClubID, c.userd5 as AsfAcctNo, c.hemail as EMail FROM eft AS e INNER JOIN client_profile AS c ON e.client_no = c.client_no WHERE e.last_mdt >= #" & txtAsOfDt.Text & "# OR c.last_mdt >= #" & txtAsOfDt.Text & "# ORDER BY e.client_no"

Thanks All!

Writing Data To A Text File Without Carriage Returns
In my app I am creating a comma seperated value text file. I am using the Print #x, command.

What I am trying to get around is having to write all of the values that I want to put on a single line of text and then printing the string. I would like to write them directly to the file but everytime I use "Print #x," it writes a new line.

Does anyone have a way around writing all of the values to a string or array and then writing them one line at a time?

I would really like to write each value down as I encounter them and then insert a carriage return when I want to. Addtionally, if there is a way around this, how do I perform that carriage return?

Thanks,

Jim

Writing Results To Text File. Spacing Between Data.
Hi

I pretty new to Visual basic 6, having only dealt with VBA I am after some advice about writing the results from my project to a text file.  I have successfully written the code (which is pretty simple stuff I know) to write the data to the text file but I need to keep the spaces between each entry the same size so that I can transfer/convert it into excel at a later date.  Is there a way to keep the spacing between the data the same for every row that is entered.  

This is difficult to explain but I have a list of checkbox's that people will either tick one or all of them.  The results from these are either 1 or 0. Then I have their username from Windows, the date, the time and then 3 text box for free text.  The problem I have is the text box results, I dont mind setting the max length in the text box parameters but this would cause a problem if they only entered a small amount of text.

I will try and show an example of what I mean.

Data would be something like this

simon 0122007 0  0  1  1  1  1  0  0 Text1  Text2 Text3
simon 0222007 0  1  0  1  1  0  0  1 Moretext1 text 2 text3

What I would like to see is:

simon 0122007 0  0  1  1  1  1  0  0 Text1       Text2    Text3
simon 0222007 0  1  0  1  1  0  0  1 Moretext1 text 2    text 3
Bascially if you try to convert the first example in Excel I could not line up the columns on 'Text1, Text2' with More text1 and text2.

I hope this explains it for you all and hope that you can help.

Many Thanks

Simon

Problem When Writing Data From Listbox To Text File (help Me)
i got 1 listbox with 2 items

Code:Private Sub Form_Load()
list1.AddItem "abc"
list1.AddItem "bde"
End Sub


Private Sub Command1()
Dim Data4 As Integer
        Data4 = FreeFile
        Open "E:abc3.txt" For Append As #Data4
        Dim ap As Integer
            For ap = 0 To list1.ListCount - 1
                Print #Data4, list1.List(ap)
            Next ap
        Close #Data4
End Sub

when i try to execute above code ... and when i check the text file (abc3.txt) i found that actually it write 3 line to the text file.
the first and second line of course are
abc
bde

the third line is a blank line.

my question is how to avoid the blank line to be written into the file.

(you can try to click the 3rd line... the mouse can point to the 3rd line.. how to make sure that the mouse pointer cannot go to 3 line but only at the end of 2nd line)

Thanks in advance.



Edited by - wtkm on 7/3/2007 6:57:29 PM

Writing 101375 Lines Of Data To A Text File.
Is it possible to write almost 101375 lines of data in a text file? I've tried several methods in writing a text file, but my computer hangs when executing my code.

Here's the code:

Dim CString as String
Dim Data(1 to 352, 1 to 288) as Integer

'Data to be writen on a text file
for i = 1 to 288
for j = 1 to 352
CString = CString & Str(Data(j,i)) & vbCrLf
Next j
Next i

I want to write the data of CString but my computer hangs when executing.

VB6 - WRITING TO A TEXT FILE -Date/Time Data
I am trying to write data to a text file by way of a query. The data is coming from joined Access 2000 tables. Everything writes to the text file properly except the 2 fields that are of DATE/TIME data type. They appear with # on either end. ie: #2003-06-15#.
It needs to appear mm/dd/yyyy without the #s. Please help!
Here is output sample and a code sample.

OUTPUT:

"10129498","C","PRUITT ","MARK ","12487 GLENGATE ","3142051540","M",#2003-06-15#,#2039-12-31#,"24.88","15"

CODE:

Open strFileName For Output As #1
Do Until strCurrent.EOF
strCurrent("account"), strCurrent("status"), strCurrent("lname"), strCurrent("fname"), strCurrent("addr"), strCurrent("hphone"), strCurrent("sex"), strCurrent("beg"), strCurrent("exp"), strCurrent("pay"), strCurrent("due"), strCurrent("eftrt"), strCurrent("accountnum"), strCurrent("ccexp"), strCurrent("email")
strCurrent.MoveNext
Loop
Close #1

QUERY:

"SELECT e.client_no as account, e.acct_type as status, e.last_name as lname, e.first_name as fname, c.address as addr, c.city, c.state, c.zip, (c.[hphoneac] & c.[hphone]) as hphone, c.wphone, c.gender as sex, e.start_date as beg, e.end_date as exp, e.monthly_fee as pay, e.billing_day as due, e.bank_aba as eftrt, e.acct_no as accountnum, e.acct_exp as ccexp, c.userd4 as ClubID, c.userd5 as AsfAcctNo, c.hemail as EMail FROM eft AS e INNER JOIN client_profile AS c ON e.client_no = c.client_no WHERE e.last_mdt >= #" & txtAsOfDt.Text & "# OR c.last_mdt >= #" & txtAsOfDt.Text & "# ORDER BY e.client_no"

Thanks All!

Writing Binary Data Using WriteFile()
Hi,

I'm trying to write binary data to a file creating using CreateFile(). The problem I am having is if the file reaches around 60Kb in size the WriteFile() function fails with error code 6, which I think is INVALID_HANDLE_VALUE.

Below is the statement used to create the file

VB Code:
hFile = CreateFile(sCurFileName, GENERIC_WRITE Or GENERIC_READ, 0, 0, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0)


sCurFileName is the name of an existing(empty) file.

Here is the function used to write data to the file.


VB Code:
Public Function StreamIncomingMsg(ByRef bData() As Byte, nLen As Long)    Dim nBytesWritten As Long    Dim nRes As Long    Dim lRes As Long    mnOffSet = mnOffSet + nLen    nRes = WriteFile(hFile, bData(1), nLen, nBytesWritten, ByVal 0&)    lRes = SetFilePointer(hFile, mnOffSet, 0, FILE_BEGIN)End Function


Does anyone know why the file can't be written to after roughly 60Kb of data. When it fails nRes has the return code of 6 as I mentioned above.

NB: hFile is declared at the module level and all this code is in the same module.

Any help appreciated.

Writing Binary Data On WinXP
Binary data is downloaded (via a 3rd party control) from a server is to write to a file locally. On Win98, the file size is the same as that on the server. However on WinXP, the file size is bigger. Since file size is used to determine if the download is successful or failed, download in WinXP fails everytime!

The file is opened with:

Code:
Open strLocalFile For Binary Access Write As intLocalFile


Data is written to file with:

Code:
dim byData() as Byte
..... (call to 3rd party control to get data and saved to bytData)...
Put intLocalFile, , bytData


Eliminating the possibility that the error could have been caused by this 3rd party control, is it possible that it's a known issue when the code run on WinXP, an extra character is automatically appened to the end of line? Please advise.

Writing To Registry With Binary Data
Hi.

I have a key in my registry and that key is in binary data format. Is there a function to change this value from VB? I tried one tutorial here that uses String values... but then the binary became a string value.

How do I change binary data registry keys from VB?

Open Text File And Read From Last Data First Until First Data
usually open file for read text file read from first data until last data right?
now i want to do is read last data first in text file until first data.

thank you

Read Data From Text File..
i'm doing a meter program..and required to display the value of meter according to the data in text file..my meter will keep running until the last record..wat i have done doesnt stop the meter..it keep looping..wat should i do to make my meter stop and show the last record value??

here is my coding,

filenum = FreeFile
Open textfile For Input As #filenum

Do Until EOF(filenum)
Input #filenum, strnumber

actual = Mid(strnumber, 11, 4)
average = Mid(strnumber, 15, 4)

Meter1.HandValue = actual
Meter2.HandValue = average

Loop

Close (1)

Read Data From Text File
I have the required data for processing as a text file. Each line of data represents a record(row) and the fields (columns) are seperated by a delimiter "|" symbol. How do I read data from the text file record by record and field by field? Codes please.
Thanks in advance.
Ram.
g_s_ramkumar@yahoo.com

Read All Data From A Text File
Is there an easy way to read all the data in a text file into a string, without looping and
reading each line to build the string? I thought you could do it with the FileSystemObject but
I can't seem to find how.
Thanks for any help.

Kris
Software Engineer
Phoenix,AZ

Read In Data From A Special Text File
Hi everyone,  

Its a special text file as it is a cross between a ini file and csv file.  I have generated this txt file from a vibration analyser that I made and the format is as follows:

[Parameters]
SampleFreq=5
NoSamples=256

[Inputs]
Ip1=1
Ip2=0

[Data]
1.23,2.11,4.56,5.4,3.1, etc

Ok.  I have written some code to read from an INI file that reads the parameters and inputs data.  But what I now need is some code that would read in the data fields (csv format) into an array.  Does anyone have any suggestions on how I might go about doing this.  

Thanks

Fozzie

Writing A Binary File
I just learned how to read input from files using Binary, and I understand it. However, I don't understand how to create my own file and write byte values to it. How would I go about making a file from scratch using binary, or appending to an already existing file? Do I have to use For Random, or just plain old For Input/output/append?

Writing To A Binary File
I'm busy writing a File transfer program for the internet. I have obtained some code on the net for sending the file byte by byte, the only problem is that it doesn't cover building that file up again. That means that I'm stuck with a file all stored up in a string variable and I have no knowledge of how to rebuild the file from there. Help!

Writing To Binary File
All

Im using the code below to write to a binary but it overwrites each time, how do i get it to add my new records to the end of each file instead of overwriting previous data

thanks

gibbo


VB Code:
Private Sub cmdWrite_Click()   Dim intFileNum As Integer   intFileNum = FreeFile 'Get a file handle.    With Empl      .ID = intID      .MonthlySalary = intSalary      .LastReviewDate = dteDate      .FirstName = strFirst      .LastName = StrLast      .Title = StrTitle      .ReviewComments(0) = Review      .ReviewComments(1) = Review1      .ReviewComments(2) = Review2   End With 'write to the file   Open "c: est.bin" For Binary As intFileNum      Put intFileNum, , Empl   Close intFileNumEnd Sub

How To Read Binary Data?
Hi,
I have a problem reading Binary file, in fact I don't know how shall I read it.
I don't know anything about the file, but that it is a mixture of meteorological data, and
I am supposed to get them out of it.
I tried to open the file in Binary File mode, but I got only no-sense-making mixture of characters. The problem is that I don't know the structure of data.
A part of the .bin file is attached to the end of the email.
All help is very welcome
TIA

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