On a Windows 98 machine I have space delimited files with a data string for
each hour of the day. I want to use a vbscript to change the value in the
4th
column to 9999 when the time stamp in the 2nd column is 0300 as in the 3rd
row here. I'm not a programmer.

JO 09030100 * 0.0266 * * * 82 * * * * * * 39 33 * * 5915
JO 09030200 * 0.0374 * * * 82 * * * * * * 81 90 * * 5913
JO 09030300 * 0.1378 * * * 82 * * * * * * 78 157 * * 5914
JO 09030400 * 0.0311 * * * 82 * * * * * * 65 210 * * 5915

Re: Find Replace by McKirahan

McKirahan
Mon Sep 11 09:24:17 CDT 2006

"David99x" <David99x@discussions.microsoft.com> wrote in message
news:2E4BCC9B-527B-4EDA-A3B5-5AB2454AE3CA@microsoft.com...
> On a Windows 98 machine I have space delimited files with a data string
for
> each hour of the day. I want to use a vbscript to change the value in the
> 4th
> column to 9999 when the time stamp in the 2nd column is 0300 as in the 3rd
> row here. I'm not a programmer.
>
> JO 09030100 * 0.0266 * * * 82 * * * * * * 39 33 * * 5915
> JO 09030200 * 0.0374 * * * 82 * * * * * * 81 90 * * 5913
> JO 09030300 * 0.1378 * * * 82 * * * * * * 78 157 * * 5914
> JO 09030400 * 0.0311 * * * 82 * * * * * * 65 210 * * 5915

So you want the result in your example to be the following?

JO 09030100 * 0.0266 * * * 82 * * * * * * 39 33 * * 5915
JO 09030200 * 0.0374 * * * 82 * * * * * * 81 90 * * 5913
JO 09030300 * 9999 * * * 82 * * * * * * 78 157 * * 5914
JO 09030400 * 0.0311 * * * 82 * * * * * * 65 210 * * 5915

Presuming that the timestamp is in the format "mmyyhhnn".

Would "0300" always start in column 8 of a row?

Is this a class assignment?



Re: Find Replace by David99x

David99x
Mon Sep 11 16:11:02 CDT 2006

The 0300 will always start in column 8 as you say. And your example is
exactly correct. This little project is for work, but not commercial work.
I spent many hours at home this weekend searching the internet for sample
code I could modify for my purpose. I was spectacularly unsuccessful,
probably because I'm not really a programmer.

It occurs to me that at some point, the "*" between the time stamp and the
number I want to replace with 9999 may someday be replace with a number
itself. So whatever ideas I get here I may need to modify at a later date.
But your representation of the output is correct at this time. Thanks for
your attention.

"McKirahan" wrote:

> "David99x" <David99x@discussions.microsoft.com> wrote in message
> news:2E4BCC9B-527B-4EDA-A3B5-5AB2454AE3CA@microsoft.com...
> > On a Windows 98 machine I have space delimited files with a data string
> for
> > each hour of the day. I want to use a vbscript to change the value in the
> > 4th
> > column to 9999 when the time stamp in the 2nd column is 0300 as in the 3rd
> > row here. I'm not a programmer.
> >
> > JO 09030100 * 0.0266 * * * 82 * * * * * * 39 33 * * 5915
> > JO 09030200 * 0.0374 * * * 82 * * * * * * 81 90 * * 5913
> > JO 09030300 * 0.1378 * * * 82 * * * * * * 78 157 * * 5914
> > JO 09030400 * 0.0311 * * * 82 * * * * * * 65 210 * * 5915
>
> So you want the result in your example to be the following?
>
> JO 09030100 * 0.0266 * * * 82 * * * * * * 39 33 * * 5915
> JO 09030200 * 0.0374 * * * 82 * * * * * * 81 90 * * 5913
> JO 09030300 * 9999 * * * 82 * * * * * * 78 157 * * 5914
> JO 09030400 * 0.0311 * * * 82 * * * * * * 65 210 * * 5915
>
> Presuming that the timestamp is in the format "mmyyhhnn".
>
> Would "0300" always start in column 8 of a row?
>
> Is this a class assignment?
>
>
>

Re: Find Replace by McKirahan

McKirahan
Mon Sep 11 17:45:33 CDT 2006

"David99x" <David99x@discussions.microsoft.com> wrote in message
news:0013AEE6-B8A5-4136-B589-654FC9D39C45@microsoft.com...
> The 0300 will always start in column 8 as you say. And your example is
> exactly correct. This little project is for work, but not commercial
work.
> I spent many hours at home this weekend searching the internet for sample
> code I could modify for my purpose. I was spectacularly unsuccessful,
> probably because I'm not really a programmer.
>
> It occurs to me that at some point, the "*" between the time stamp and the
> number I want to replace with 9999 may someday be replace with a number
> itself. So whatever ideas I get here I may need to modify at a later
date.
> But your representation of the output is correct at this time. Thanks for
> your attention.
>
> "McKirahan" wrote:
>
> > "David99x" <David99x@discussions.microsoft.com> wrote in message
> > news:2E4BCC9B-527B-4EDA-A3B5-5AB2454AE3CA@microsoft.com...
> > > On a Windows 98 machine I have space delimited files with a data
string
> > for
> > > each hour of the day. I want to use a vbscript to change the value in
the
> > > 4th
> > > column to 9999 when the time stamp in the 2nd column is 0300 as in the
3rd
> > > row here. I'm not a programmer.
> > >
> > > JO 09030100 * 0.0266 * * * 82 * * * * * * 39 33 * * 5915
> > > JO 09030200 * 0.0374 * * * 82 * * * * * * 81 90 * * 5913
> > > JO 09030300 * 0.1378 * * * 82 * * * * * * 78 157 * * 5914
> > > JO 09030400 * 0.0311 * * * 82 * * * * * * 65 210 * * 5915
> >
> > So you want the result in your example to be the following?
> >
> > JO 09030100 * 0.0266 * * * 82 * * * * * * 39 33 * * 5915
> > JO 09030200 * 0.0374 * * * 82 * * * * * * 81 90 * * 5913
> > JO 09030300 * 9999 * * * 82 * * * * * * 78 157 * * 5914
> > JO 09030400 * 0.0311 * * * 82 * * * * * * 65 210 * * 5915
> >
> > Presuming that the timestamp is in the format "mmyyhhnn".
> >
> > Would "0300" always start in column 8 of a row?
> >
> > Is this a class assignment?
> >
> >
> >



Re: Find Replace by McKirahan

McKirahan
Mon Sep 11 17:51:49 CDT 2006

"David99x" <David99x@discussions.microsoft.com> wrote in message
news:0013AEE6-B8A5-4136-B589-654FC9D39C45@microsoft.com...
> The 0300 will always start in column 8 as you say. And your example is
> exactly correct. This little project is for work, but not commercial
work.
> I spent many hours at home this weekend searching the internet for sample
> code I could modify for my purpose. I was spectacularly unsuccessful,
> probably because I'm not really a programmer.
>
> It occurs to me that at some point, the "*" between the time stamp and the
> number I want to replace with 9999 may someday be replace with a number
> itself. So whatever ideas I get here I may need to modify at a later
date.
> But your representation of the output is correct at this time. Thanks for
> your attention.

(Ignore my other post of a few minutes ago.)

Try this. Watch for word-wrap.

Option Explicit
'*
'* Declare Constants
'*
Const cVBS = "replacer.vbs"
Const cOT1 = "replacer1.txt"
Const cOT2 = "replacer2.txt"
'*
'* Declare Variables
'*
Dim arrOT1
Dim intOT1
intOT1 = 0
Dim strOT1
Dim strOT2
'*
'* Declare Objects
'*
Dim objFSO
Set objFSO = CreateObject("Scripting.FileSystemObject")
Dim objOT1
Set objOT1 = objFSO.OpenTextFile(cOT1,1)
Dim objOT2
Set objOT2 = objFSO.OpenTextFile(cOT2,2,true)
'*
'* Read, Replace, Write
'*
Do While Not objOT1.AtEndOfStream
intOT1 = intOT1 + 1
strOT1 = objOT1.ReadLine()
arrOT1 = Split(strOT1," ")
If Right(arrOT1(1),4) = "0300" Then
arrOT1(3) = "9999"
End If
strOT2 = Join(arrOT1," ")
objOT2.WriteLine(strOT2)
Loop
'*
'* Destroy Objects
'*
Set objOT1 = Nothing
Set objOT2 = Nothing
Set objFSO = Nothing
'*
'* Completion Message
'*
MsgBox intOT1 & " records",vbInformation,cVBS




Re: Find Replace by David99x

David99x
Tue Sep 12 01:17:02 CDT 2006

Thank you very much for your help. I can see how this will work. However,
I'm getting an error "Subscript out of range: '[number: 1]'" on this line: If
Right(arrOT1(1),4) = "0300" Then
I tried everything I can think of to get past the error, but no luck. I'm
stuck. In addition, I wanted to just save the original file with the
changes, not write it to another file.
Thanks again. I see your name quite a bit as I search around for ways to do
this myself. I'm glad you are helping me.

"McKirahan" wrote:

> "David99x" <David99x@discussions.microsoft.com> wrote in message
> news:0013AEE6-B8A5-4136-B589-654FC9D39C45@microsoft.com...
> > The 0300 will always start in column 8 as you say. And your example is
> > exactly correct. This little project is for work, but not commercial
> work.
> > I spent many hours at home this weekend searching the internet for sample
> > code I could modify for my purpose. I was spectacularly unsuccessful,
> > probably because I'm not really a programmer.
> >
> > It occurs to me that at some point, the "*" between the time stamp and the
> > number I want to replace with 9999 may someday be replace with a number
> > itself. So whatever ideas I get here I may need to modify at a later
> date.
> > But your representation of the output is correct at this time. Thanks for
> > your attention.
>
> (Ignore my other post of a few minutes ago.)
>
> Try this. Watch for word-wrap.
>
> Option Explicit
> '*
> '* Declare Constants
> '*
> Const cVBS = "replacer.vbs"
> Const cOT1 = "replacer1.txt"
> Const cOT2 = "replacer2.txt"
> '*
> '* Declare Variables
> '*
> Dim arrOT1
> Dim intOT1
> intOT1 = 0
> Dim strOT1
> Dim strOT2
> '*
> '* Declare Objects
> '*
> Dim objFSO
> Set objFSO = CreateObject("Scripting.FileSystemObject")
> Dim objOT1
> Set objOT1 = objFSO.OpenTextFile(cOT1,1)
> Dim objOT2
> Set objOT2 = objFSO.OpenTextFile(cOT2,2,true)
> '*
> '* Read, Replace, Write
> '*
> Do While Not objOT1.AtEndOfStream
> intOT1 = intOT1 + 1
> strOT1 = objOT1.ReadLine()
> arrOT1 = Split(strOT1," ")
> If Right(arrOT1(1),4) = "0300" Then
> arrOT1(3) = "9999"
> End If
> strOT2 = Join(arrOT1," ")
> objOT2.WriteLine(strOT2)
> Loop
> '*
> '* Destroy Objects
> '*
> Set objOT1 = Nothing
> Set objOT2 = Nothing
> Set objFSO = Nothing
> '*
> '* Completion Message
> '*
> MsgBox intOT1 & " records",vbInformation,cVBS
>
>
>
>

Re: Find Replace by David99x

David99x
Tue Sep 12 01:43:01 CDT 2006

Disregard previous message related to an error running the script. For
whatever reason, the script started working as soon as I sent the message.
Anyway, I still need the script make the changes to the original text file
and save that file.

"McKirahan" wrote:

> "David99x" <David99x@discussions.microsoft.com> wrote in message
> news:0013AEE6-B8A5-4136-B589-654FC9D39C45@microsoft.com...
> > The 0300 will always start in column 8 as you say. And your example is
> > exactly correct. This little project is for work, but not commercial
> work.
> > I spent many hours at home this weekend searching the internet for sample
> > code I could modify for my purpose. I was spectacularly unsuccessful,
> > probably because I'm not really a programmer.
> >
> > It occurs to me that at some point, the "*" between the time stamp and the
> > number I want to replace with 9999 may someday be replace with a number
> > itself. So whatever ideas I get here I may need to modify at a later
> date.
> > But your representation of the output is correct at this time. Thanks for
> > your attention.
>
> (Ignore my other post of a few minutes ago.)
>
> Try this. Watch for word-wrap.
>
> Option Explicit
> '*
> '* Declare Constants
> '*
> Const cVBS = "replacer.vbs"
> Const cOT1 = "replacer1.txt"
> Const cOT2 = "replacer2.txt"
> '*
> '* Declare Variables
> '*
> Dim arrOT1
> Dim intOT1
> intOT1 = 0
> Dim strOT1
> Dim strOT2
> '*
> '* Declare Objects
> '*
> Dim objFSO
> Set objFSO = CreateObject("Scripting.FileSystemObject")
> Dim objOT1
> Set objOT1 = objFSO.OpenTextFile(cOT1,1)
> Dim objOT2
> Set objOT2 = objFSO.OpenTextFile(cOT2,2,true)
> '*
> '* Read, Replace, Write
> '*
> Do While Not objOT1.AtEndOfStream
> intOT1 = intOT1 + 1
> strOT1 = objOT1.ReadLine()
> arrOT1 = Split(strOT1," ")
> If Right(arrOT1(1),4) = "0300" Then
> arrOT1(3) = "9999"
> End If
> strOT2 = Join(arrOT1," ")
> objOT2.WriteLine(strOT2)
> Loop
> '*
> '* Destroy Objects
> '*
> Set objOT1 = Nothing
> Set objOT2 = Nothing
> Set objFSO = Nothing
> '*
> '* Completion Message
> '*
> MsgBox intOT1 & " records",vbInformation,cVBS
>
>
>
>

Re: Find Replace by McKirahan

McKirahan
Tue Sep 12 08:36:29 CDT 2006

"David99x" <David99x@discussions.microsoft.com> wrote in message
news:14132938-A51E-47AF-A50F-42BEE2B331F1@microsoft.com...
> Disregard previous message related to an error running the script. For
> whatever reason, the script started working as soon as I sent the message.
> Anyway, I still need the script make the changes to the original text file
> and save that file.

Try this. Watch for word-wrap.

This version skips blank lines in case there's a blank
line at the end of the file; (i.e. an extra CrLf).

It first reads the entire file then replaces the string
when it is found then rewrites the file.

Change the value of "cOTF" to meet your needs.

Option Explicit
'*
'* Declare Constants
'*
Const cVBS = "replacer.vbs"
Const cOTF = "replacer.txt"
'*
'* Declare Variables
'*
Dim arrOTF
Dim intOTF
intOTF = 0
Dim strOTF
Dim arrLIN
Dim intLIN
intLIN = 0
Dim strLIN
'*
'* Declare Objects
'*
Dim objFSO
Set objFSO = CreateObject("Scripting.FileSystemObject")
Dim objOTF
'*
'* Read File
'*
Set objOTF = objFSO.OpenTextFile(cOTF,1)
strOTF = objOTF.ReadAll
Set objOTF = Nothing
'*
'* Replace String
'*
arrOTF = Split(strOTF,vbCrLf)
For intOTF = 0 To UBound(arrOTF)
strLIN = arrOTF(intOTF)
If strLIN <> "" Then
intLIN = intLIN + 1
arrLIN = Split(strLIN," ")
If Right(arrLIN(1),4) = "0300" Then
arrLIN(3) = "9999"
End If
strLIN = Join(arrLIN," ")
End If
arrOTF(intOTF) = strLIN
Next
'*
'* Write File
'*
strOTF = Join(arrOTF,vbCrLf)
Set objOTF = objFSO.OpenTextFile(cOTF,2,true)
objOTF.WriteLine(strOTF)
Set objOTF = Nothing
'*
'* Destroy Objects
'*
Set objFSO = Nothing
'*
'* Completion Message
'*
MsgBox intLIN & " records",vbInformation,cVBS



Re: Find Replace by David99x

David99x
Tue Sep 12 10:01:03 CDT 2006

That works like a champ. The script does exactly what I need. Thank you
very much.

"McKirahan" wrote:

> "David99x" <David99x@discussions.microsoft.com> wrote in message
> news:14132938-A51E-47AF-A50F-42BEE2B331F1@microsoft.com...
> > Disregard previous message related to an error running the script. For
> > whatever reason, the script started working as soon as I sent the message.
> > Anyway, I still need the script make the changes to the original text file
> > and save that file.
>
> Try this. Watch for word-wrap.
>
> This version skips blank lines in case there's a blank
> line at the end of the file; (i.e. an extra CrLf).
>
> It first reads the entire file then replaces the string
> when it is found then rewrites the file.
>
> Change the value of "cOTF" to meet your needs.
>
> Option Explicit
> '*
> '* Declare Constants
> '*
> Const cVBS = "replacer.vbs"
> Const cOTF = "replacer.txt"
> '*
> '* Declare Variables
> '*
> Dim arrOTF
> Dim intOTF
> intOTF = 0
> Dim strOTF
> Dim arrLIN
> Dim intLIN
> intLIN = 0
> Dim strLIN
> '*
> '* Declare Objects
> '*
> Dim objFSO
> Set objFSO = CreateObject("Scripting.FileSystemObject")
> Dim objOTF
> '*
> '* Read File
> '*
> Set objOTF = objFSO.OpenTextFile(cOTF,1)
> strOTF = objOTF.ReadAll
> Set objOTF = Nothing
> '*
> '* Replace String
> '*
> arrOTF = Split(strOTF,vbCrLf)
> For intOTF = 0 To UBound(arrOTF)
> strLIN = arrOTF(intOTF)
> If strLIN <> "" Then
> intLIN = intLIN + 1
> arrLIN = Split(strLIN," ")
> If Right(arrLIN(1),4) = "0300" Then
> arrLIN(3) = "9999"
> End If
> strLIN = Join(arrLIN," ")
> End If
> arrOTF(intOTF) = strLIN
> Next
> '*
> '* Write File
> '*
> strOTF = Join(arrOTF,vbCrLf)
> Set objOTF = objFSO.OpenTextFile(cOTF,2,true)
> objOTF.WriteLine(strOTF)
> Set objOTF = Nothing
> '*
> '* Destroy Objects
> '*
> Set objFSO = Nothing
> '*
> '* Completion Message
> '*
> MsgBox intLIN & " records",vbInformation,cVBS
>
>
>

Re: Find Replace by Dr

Dr
Wed Sep 13 09:07:28 CDT 2006

JRS: In article <2E4BCC9B-527B-4EDA-A3B5-5AB2454AE3CA@microsoft.com>,
dated Sat, 9 Sep 2006 22:50:02 remote, seen in news:microsoft.public.scr
ipting.vbscript, David99x <David99x@discussions.microsoft.com> posted :
>On a Windows 98 machine I have space delimited files with a data string for
>each hour of the day. I want to use a vbscript to change the value in the
>4th
>column to 9999 when the time stamp in the 2nd column is 0300 as in the 3rd
>row here. I'm not a programmer.

Then don't use a programming language. Use a scripted text editor such
as MiniTrue (or use a programmer).

>JO 09030300 * 0.1378 * * * 82 * * * * * * 78 157 * * 5914

mtr -x+ *.txt ^(.{7}0300\D*)([\d\.]*) = "\1 9999"

will do it neatly. When you're satisfied that it is right, use the -n
option to kill prompts.

That takes start-of-line, 7 of any character, then 0300, then any non-
digit, as \1 ; then any string of digits and dots (which would be \2)
and replaces the characters by what is shown. You did not ask for the
two spaces, which maintain alignment.

You might prefer to specify the initial characters more exactly, maybe
as \w\d\s\d{4} - letter digit whitespace four-digits.

--
© John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 MIME. ©
Web <URL:http://www.merlyn.demon.co.uk/> - FAQish topics, acronyms, & links.
I find MiniTrue useful for viewing/searching/altering files, at a DOS prompt;
free, DOS/Win/UNIX, <URL:http://www.idiotsdelight.net/minitrue/>