473,414 Members | 1,980 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,414 software developers and data experts.

Help with low level file reading (Open as Input, etc, etc)

I've an existing program I need to tweak that can open a non-text file at low level, find certain strings and replace with another, and write back to a new file.

The string replacement bit isn't a problem as that already works, the trouble is reading the file and writing it back.
At the moment, I'm just trying to read it, and write it back and check the file is exactly the same as originial.

Code is below, but the problems I'm encountering are an end of file error and it seems to be interpretating nulls as VBCrlf.

So for example, if you imagine # is a null, the string aaaa#444#dddd becomes

aaaa

4444

dddd

Not good!

Here's the code extract, SourceFile comes from the window interface.

Expand|Select|Wrap|Line Numbers
  1. fnum1 = FreeFile
  2. Open SourceFile For Binary As fnum1
  3. fnum2 = FreeFile
  4. Open Left(SourceFile, Len(Trim(SourceFile)) - 4) & "2.NIF" For Append As fnum2
  5. Do While Not EOF(fnum1)
  6.     Line Input #fnum1, DataLine
  7.     OutputData = OutputData + DataLine
  8. Loop
  9. Print #fnum2, OutputData;
  10. Close fnum1
  11. Close fnum2
  12.  
Oct 26 '06 #1
1 3590
Killer42
8,435 Expert 8TB
I'd say you are mixing up your file modes. Basically, if you are dealing with plain ASCII text, you can Open for Input, Out or Append, and use Input # and Print # to read/write. If you are dealing with non-text data which could have weird and wonderful characters, use Binary mode (for both files) and Get/Put to read/write them.

Note, I'm almost certain that EOF won't work properly for a Binary-mode file. Could be wrong, but if not you may need to track the number of bytes you transfer, and compare it to the number of bytes in the file (picked up using something like Lof() function at the start) to know when you're finished.
Oct 27 '06 #2

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

Similar topics

2
by: nephish | last post by:
Hey there, i am trying to write an online application using the cgi module. what i want to do is have an html form display a drop-down list and have the values of that list be the lines of text...
8
by: baustin75 | last post by:
Posted: Mon Oct 03, 2005 1:41 pm Post subject: cannot mail() in ie only when debugging in php designer 2005 -------------------------------------------------------------------------------- ...
2
by: Parker.Jim | last post by:
I need to write a program which performs word subsitutions on a text file. The program should input the names of three text files: the source file that will be "edited", a text file that contains...
7
by: Novice Computer User | last post by:
Hi. Can somebody PLEASE help. I have spent hours on this.. but I am a total novice and can't seem to figure it out. Here is a .php script. Right now, the minimum amount of time (i.e. duration)...
2
by: nnimod | last post by:
Hi. I'm having trouble reading some unicode files. Basically, I have to parse certain files. Some of those files are being input in Japanese, Chinese etc. The easiest way, I figured, to distinguish...
4
by: lsu420luv | last post by:
'i have been working on this assignment for like 45 hours. the file reads from Piano.data and outputs into report.out. I have everything working, except for the fact that it will not repeat until...
0
by: gunimpi | last post by:
http://www.vbforums.com/showthread.php?p=2745431#post2745431 ******************************************************** VB6 OR VBA & Webbrowser DOM Tiny $50 Mini Project Programmer help wanted...
13
by: anant | last post by:
Hi all The below code is reading string and then tokenizin it and reading all the info. But i want to call a csv file and it should then read a string from dt file. So what midification should i...
12
by: adamurbas | last post by:
ya so im pretty much a newb to this whole python thing... its pretty cool but i just started today and im already having trouble. i started to use a tutorial that i found somewhere and i followed...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

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

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