Change value in an indexed text file

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?

Thanks.
SINCOAsked:
Who is Participating?
 
Guy Hengel [angelIII / a3]Connect With a Mentor Billing EngineerCommented:
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
wend
ts.close
set ts = fso.OpenTextStream("yourfile", 2)
ts.write d
ts.close
0
 
Guy Hengel [angelIII / a3]Billing EngineerCommented:
read the file and rewrite it with the values changed
0
 
SINCOAuthor Commented:
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?
0
Cloud Class® Course: MCSA MCSE Windows Server 2012

This course teaches how to install and configure Windows Server 2012 R2.  It is the first step on your path to becoming a Microsoft Certified Solutions Expert (MCSE).

 
SINCOAuthor Commented:
I like it. Looks simple. I'll accept yr answer when I get it to work. Thanks
0
 
SINCOAuthor Commented:
Great, it works. But using OpenTextFile. Thanks again dude.
0
 
Guy Hengel [angelIII / a3]Billing EngineerCommented:
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...
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.