hi
my requirement is read the data from the text file through vb. then calculate the data and write the result on the same text file where the data has retrived thru vb 6.0. how 2 implement the namespace in vb 6.0
i had read the text file by using
Dim sfil As String
Dim dd
Dim schunk As String
Dim nSourceFile As Integer, sText As String
sfil = "E:\proposed.tx t"
nSourceFile = FreeFile
Open sfil For Input As #nSourceFile
Do While Not EOF(1)
Line Input #1, schunk
then i had done the calculation . now i want 2 write the result in the same text file.
can anyone help me regarding this issue.
regards
vivek
11 22548
If you want to do this for more than one record, then I don't think a plain text file will work. You might have to go with a "random access" or "binary mode" text file. That is, one which allows you to read/write at specific points.
Look into the Binary and Random options on the Open statement. I'm about to leave work, so won't be with you for a while...
If there is only one record in the file, then the simplest thing might be just to Close it then Open it again before using Print # to write the result.
hi
you can't use print just like that because your in the input-mode.
once you closed your textfile and open this open it again in output-mode, you will lose all information.
so, suggest you open in APPEND-mode
and use Print # to place your data at the end of the existing data.
have a simular problem...
>so, suggest you open in APPEND-mode
>and use Print # to place your data at the end of the existing data.
But how do you edit a file. How can you for example add data in the midle of a textfile?
Say you have a textfile with lots and lots of text. Somewhere in that text there is a word, say "october", and you want to ad a few lines right after that. One could of course remove all text after the word "october", and store it somewhere, Than apend the lines you want to add, and finally append the stored text at the end of the file again. But that isn't a nice solution. Especially for large files.
I read somthing in this tread about opening the file in binary mode or use random access-mode. But you cant edit a textfile in these modes, can you? Not if you want to be able to open it in a texteditor later. So how do you solve this?
This migth be a newbie question, so have patiance with me. :)
have a simular problem...
>so, suggest you open in APPEND-mode
>and use Print # to place your data at the end of the existing data.
But how do you edit a file. How can you for example add data in the midle of a textfile?
Say you have a textfile with lots and lots of text. Somewhere in that text there is a word, say "october", and you want to ad a few lines right after that. One could of course remove all text after the word "october", and store it somewhere, Than apend the lines you want to add, and finally append the stored text at the end of the file again. But that isn't a nice solution. Especially for large files.
I read somthing in this tread about opening the file in binary mode or use random access-mode. But you cant edit a textfile in these modes, can you? Not if you want to be able to open it in a texteditor later. So how do you solve this?
This migth be a newbie question, so have patiance with me. :)
Looks like you answered you own question. Sometimes the answer may not be as elegant as you would like. -
stLeftText = Left(stAllText, lngInsertPoint)
-
stLeftText = stLeftText & stTextToInsert
-
stAllText = stLeftText & Right(stAllText, Len(stAllText) - lngInsertPoint)
-
I read somthing in this tread about opening the file in binary mode or use random access-mode. But you cant edit a textfile in these modes, can you? Not if you want to be able to open it in a texteditor later. So how do you solve this?
That's not strictly true. A text file is a text file. The different modes just allow you to manipulate it (or any type of file) in different ways.
Random is useful for working with something like a database, where you have records of (up to) a certain, specified length. You can read and write any specified record, without affecting the rest of the file.
Binary mode is probably the most powerful, allowing you to read and write any number of bytes to/from any point in the file. So for editing purposes, it could be quite useful. However, the problem you run into is when things change in length. If you wanted to change the word "CAT" to the word "DOG" for example, you could simply overwrite it in place. But if you wanted to change "CAT" to "WOMBAT", then all of the subsequent contents of the file would have to shift right three places to make room.
Normal Input/Output/Append mode is by far the simplest to use, but has a number of restrictions. It does, however, allow you to do things like the Line Input statement which inputs to the next line break, and so is more intuitive to use.
As willakawill pointed out, probably the simplest way to insert something in the middle of a text file is to read in the entire file, insert the text where you want it, then write the whole thing out again. Depending on how important the data is, you may or may not want to take precautions such as making a backup copy. This kind of procedure is performed more often than you might think - take most ZIP utilities, for example. When adding to an existing archive, they will typically do something like: - copy it to a temporary file
- append new data to the temp file
- delete the original file
- rename the new file to the original name
The point of all this, of course, is that it minimises the chance of losing your original data if anything goes wrong along the way.
This migth be a newbie question, so have patiance with me. :)
Without newbies, this place would be no fun at all.
Hello and thanks for your suggestions people!!
The awnser about storing in records seemed interesting. If I understood correctly its possible to store data anywhere inside a textfile, without corrupting the file. I have looked around for this on the web and it appears a bit complicated and hard to understand. Will look into it more later. Might learn someting even if it does not work well in this case. Anyway, thanks for the tip.
Have a question about the simplier way to solve the problem. (When you just read the entire file, add the new data, and then put it all back again). How much data can you store in a string variable? We're talking abaout thousends of lines here. I remeber playing a litle with perl and shellscripting a few years ago. Than I processed a large amount of files with a script, and the files ended up concatenated. Is there a risk for this to happend, if I use the code suggested by willakawill for example?
Hello and thanks for your suggestions people!!
... Might learn someting even if it does not work well in this case. Anyway, thanks for the tip.
That's the spirit! :)
Have a question about the simplier way to solve the problem. (When you just read the entire file, add the new data, and then put it all back again). How much data can you store in a string variable? We're talking abaout thousends of lines here. I remeber playing a litle with perl and shellscripting a few years ago. Than I processed a large amount of files with a script, and the files ended up concatenated. Is there a risk for this to happend, if I use the code suggested by willakawill for example?
The files will only end up concatenated if you explicitly do so. As I often say to people at work, possibly the biggest problem with computers is that they do exactly what you tell them to do, not what you want them to do.
If willakawill doesn't beat me to it, and you still need help, I'll try to get back to you at lunch time (it's mid-morning here now) or after work. Can't spare more time at the moment.
With this sort of thing though, the best way to learn is just to try out everything you can think of, and see what happens. As long as it's on unimportant data, of course. :)
Sorry, forgot to mention. Unless you're talking about really huge data volumes, there's no real restriction on string sizes these days.
The upper limit is probably your available RAM (physical or virtual, not sure). And if you don't have room for it all in there, just read and write a line (or bigger chunk) at a time.
Sorry, forgot to mention. Unless you're talking about really huge data volumes, there's no real restriction on string sizes these days.
The upper limit is probably your available RAM (physical or virtual, not sure). And if you don't have room for it all in there, just read and write a line (or bigger chunk) at a time.
I guess there is no problem to store a few hundred kilobytes of text in a string variable then. Problem solved. :)
.... Than I processed a large amount of files with a script, and the files ended up concatenated. Is there a risk for this to happend, if I use the code suggested by willakawill for example?
I realize now that I wrote concatenated, when I really ment truncated. :\ Bet it makes more sense now. :)
Anyway, Im glad you people took time to look at my problems. Great forum.
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: Xah Lee |
last post by:
20050207 text pattern matching
# -*- coding: utf-8 -*-
# Python
# suppose you want to replace all strings of the form
# <img src="some.gif" width="30" height="20">
# to
# <img src="some.png" width="30" height="20">
# in your html files.
|
by: Abhishek |
last post by:
Hi! Everyone
I have a small issue, if anyone could help me out
I need to upload user files to my website thru my web application. something
similar to attaching a file to the mail.
I know one way of doing it is thru HTTP but that gives a limitation of 4mb
I was doing it thru FTP and it worked fine during preliminary testing on the
localhost.
but when i tried it doing thru intranet it gave me a problem,
|
by: MPF |
last post by:
Alas, I surrender...
In a file from a COBOL dump, which is in ASCII, one of the fields is defined
as S9(9) V99 Value +0.
The value in this location is 0000018922D, which according to the author of
the source, translates to 00000189224.
How can this be translated via .Net? I've tried StreamReader and trying to
convert everything to bytes, but I end up with the same value (0000018922D).
|
by: Dave S |
last post by:
I have a lot of forms on our web site that require the user to fill out
information and submit it back to us. currently the information comes back as
name value pair. The our employee's then has to go thru all this code and
fill in a template with the data and print the info out. It would be so much
easier if we could have a button that would access the file/send/page by
email button on IE. Using asp.net 2 the my.computer.keyboard.sendkey...
|
by: Edson Peacock |
last post by:
I have a report with sub reports, one of the subreports have 12 text boxes
that are 2" high and I want them all to grow if one goes to 3" high.
If anyone has any suggestions they are very much appreciated.
Thanks
| |
by: asdfghjkl2007 |
last post by:
Hy
Is it possible to write a html script that acts as a server ?
someting like:
- it should start when a client opens the web page on witch it is housted
- receve a stream o bits from the client ( from witch it will extract the necessary commands)
- open another stream to the same client thru witch it should send a part of a file that is stored in the same directory as the web page
- open another conection to the same...
|
by: =?Utf-8?B?R2FuZXNoIE11dGh1dmVsdQ==?= |
last post by:
Hello All,
Our application write logs to a file in a folder. Before our application
starts writing to that file, I want to check if the current user has write
access to that file, for example, "c:\temp\LogFile.txt".
I see several articles for setting file access permissions, getting file
access permissions for a given user or current user - but the current user
could also gain write access to the same file not just by explicit permssion...
|
by: shantanu |
last post by:
Hi
i am trying to upload a txt file thru this code, but its not updating
the data. is this code fine.
Or can anybody please suggest me some other meathod to do the same.
its urgent please help
regards
shantanu
WebClient client = new WebClient();
|
by: Ira.Kovac |
last post by:
Hello All,
I'd greatly appreciate if you can take a look at the task I need help
with.
It'd be outstanding if someone can provide some sample Python code.
Thanks a lot,
Ira
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
| |
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |