Change value in an indexed text file

Posted on 2006-05-10
Medium Priority
Last Modified: 2010-05-01
I have indexed text file with data as follows:

0 3051
1 0
2 0
3 0
4 0
5 0
6 0
7 0
8 0
9 0
10 10
11 1
12 25
13 1
14 1000
15 2
16 3
17 20
18 0
19 0
20 -49.73201

How can i change individual values without messing up the index number?

Question by:SINCO
  • 3
  • 3
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 16647350
read the file and rewrite it with the values changed

Author Comment

ID: 16647459
Yeah, well done. But how do I change the value. Eg. how do i change the value corresponding to index 15 from 2 to 6?
LVL 143

Accepted Solution

Guy Hengel [angelIII / a3] earned 2000 total points
ID: 16647537
dim fso as object
set fso = createobject("scripting.filesystemobject")

dim ts as object
dim l as string
dim p() as string
dim d as string

set ts = fso.OpenTextstream("yourfile", 1)
while not ts.AtEndOfStream
  l = ts.readline
  p = split(l, " ")
  if p(0) = 15 then
    p(1) = 6
  end if
  d = d & join(p, " ") & vbcrlf
set ts = fso.OpenTextStream("yourfile", 2)
ts.write d
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.


Author Comment

ID: 16647602
I like it. Looks simple. I'll accept yr answer when I get it to work. Thanks

Author Comment

ID: 16647946
Great, it works. But using OpenTextFile. Thanks again dude.
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 16648007
Glad I could help, sorry for the wrong function name (As I don't have vb here....)

the first comment was to start the direction, so I could detect what your level of understanding of the situation was...

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question