Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > VB Script

Vista - Incrementing number in INI file

Reply
 
Old 05-04-2009   #1 (permalink)
bob


 
 

Incrementing number in INI file

hi,
i have an ini file which i need to increment the numbers from 0-9 and then
restart, so 0,1...8,9,0,1 etc for one of the lines.

The file looks like this
[start]
TIMS_0=1
TIMS_1=0
TIMS_2=1
BOB=1
BOB=12

i need to increment TIMS_1 by 1 (until it reaches 9 when the next number
would be 0) each time the user starts the program

i would really appreciate some help on this

cheers

b



My System SpecsSystem Spec
Old 05-04-2009   #2 (permalink)
Pegasus [MVP]


 
 

Re: Incrementing number in INI file


"bob" <bob@xxxxxx> wrote in message
news:ugKpdLMzJHA.1416@xxxxxx
Quote:

> hi,
> i have an ini file which i need to increment the numbers from 0-9 and then
> restart, so 0,1...8,9,0,1 etc for one of the lines.
>
> The file looks like this
> [start]
> TIMS_0=1
> TIMS_1=0
> TIMS_2=1
> BOB=1
> BOB=12
>
> i need to increment TIMS_1 by 1 (until it reaches 9 when the next number
> would be 0) each time the user starts the program
>
> i would really appreciate some help on this
>
> cheers
>
> b
I think you need to put a little more work into your functional
specification. It is possible to interpret your post in several ways:
- You wish to read the .ini file into a two dimenasional array like so:
TIMS_0 / 1
TIMS_1 / 0
TIMS_2 / 1
BOB / 1
BOB / 12
You now wish to add 1 to each second element so that it looks like so:
TIMS_0 / 2
TIMS_1 / 1
TIMS_2 / 2
BOB / 2
BOB / 13
- You pick the element that corresponds to the logged-on user, e.g. TIMS_0,
read his number (=1), then increment it and put it up on the screen.
- You do something else to one, some or all of the lines, then write them
back into the .ini file.
- You keep adding new lines to the .ini file after adding 1 to some or all
of the lines.
- etc. etc.
It would help if you posted the code you have so far. You'll get a much
better response when you give repondents an opportunity to help you with
existing code than when you ask them to do the whole job for you.


My System SpecsSystem Spec
Old 05-04-2009   #3 (permalink)
ekkehard.horner


 
 

Re: Incrementing number in INI file

bob schrieb:
Quote:

> hi,
> i have an ini file which i need to increment the numbers from 0-9 and then
> restart, so 0,1...8,9,0,1 etc for one of the lines.
>
> The file looks like this
> [start]
> TIMS_0=1
> TIMS_1=0
> TIMS_2=1
> BOB=1
> BOB=12
>
> i need to increment TIMS_1 by 1 (until it reaches 9 when the next number
> would be 0) each time the user starts the program
>
> i would really appreciate some help on this
[...]

I second Pegasus' request for a more lucid specification. But if you want
to increment the TIMS_1 value (only), this will get you started:

Option Explicit

Dim sFSpec : sFSpec = ".\timsini.ini"
Dim oFS : Set oFS = CreateObject( "Scripting.FileSystemObject" )
Dim oRE : Set oRE = New RegExp
oRE.Multiline = True
oRE.Pattern = "^(TIMS_1=)(\d)(\s*)$"
Dim sTxt
sTxt = oFS.OpenTextFile( sFSpec ).ReadAll()
WScript.Echo sTxt
sTxt = oRE.Replace( sTxt, GetRef( "replTims1" ) )
WScript.Echo sTxt
oFS.CreateTextFile( sFSpec, True ).Write sTxt
WScript.Quit 0

Function replTims1( sMatch, sCapture0, sDigit, sCapture2, nPos, sSource )
Dim nDigit : nDigit = CByte( sDigit )
If nDigit = 9 Then
nDigit = 0
Else
nDigit = nDigit + 1
End If
replTims1 = sCapture0 & nDigit & sCapture2
End Function

output:

C:\wis\_vbs\0506\dev\forum
cscript timsini.vbs
[start]
TIMS_0=1
TIMS_1=0
TIMS_2=1
BOB=1
BOB=12

[start]
TIMS_0=1
TIMS_1=1
TIMS_2=1
BOB=1
BOB=12

....
cscript timsini.vbs
[start]
TIMS_0=1
TIMS_1=1
....

[start]
TIMS_0=1
TIMS_1=2
....

....
cscript timsini.vbs
[start]
TIMS_0=1
TIMS_1=8

[start]
TIMS_0=1
TIMS_1=9
....

cscript timsini.vbs
[start]
TIMS_0=1
TIMS_1=9
....

[start]
TIMS_0=1
TIMS_1=0
....
My System SpecsSystem Spec
Old 05-04-2009   #4 (permalink)
bob


 
 

Re: Incrementing number in INI file

my apologies for not being clear enough

ekkehard, your assumption was correct, i wish to only increment the
numerical value of TIMS_1, to change it to TIMS_1=1, TIMS_1=2 etc, what you
did is perfect and exactly what i needed, i was striuggling with the
extraction of the number sequence so you helped out miles

bob



"ekkehard.horner" <ekkehard.horner@xxxxxx> wrote in message
news:49ff1935$0$31343$9b4e6d93@xxxxxx-online.net...
Quote:

> bob schrieb:
Quote:

>> hi,
>> i have an ini file which i need to increment the numbers from 0-9 and
>> then restart, so 0,1...8,9,0,1 etc for one of the lines.
>>
>> The file looks like this
>> [start]
>> TIMS_0=1
>> TIMS_1=0
>> TIMS_2=1
>> BOB=1
>> BOB=12
>>
>> i need to increment TIMS_1 by 1 (until it reaches 9 when the next number
>> would be 0) each time the user starts the program
>>
>> i would really appreciate some help on this
> [...]
>
> I second Pegasus' request for a more lucid specification. But if you want
> to increment the TIMS_1 value (only), this will get you started:
>
> Option Explicit
>
> Dim sFSpec : sFSpec = ".\timsini.ini"
> Dim oFS : Set oFS = CreateObject( "Scripting.FileSystemObject" )
> Dim oRE : Set oRE = New RegExp
> oRE.Multiline = True
> oRE.Pattern = "^(TIMS_1=)(\d)(\s*)$"
> Dim sTxt
> sTxt = oFS.OpenTextFile( sFSpec ).ReadAll()
> WScript.Echo sTxt
> sTxt = oRE.Replace( sTxt, GetRef( "replTims1" ) )
> WScript.Echo sTxt
> oFS.CreateTextFile( sFSpec, True ).Write sTxt
> WScript.Quit 0
>
> Function replTims1( sMatch, sCapture0, sDigit, sCapture2, nPos, sSource )
> Dim nDigit : nDigit = CByte( sDigit )
> If nDigit = 9 Then
> nDigit = 0
> Else
> nDigit = nDigit + 1
> End If
> replTims1 = sCapture0 & nDigit & sCapture2
> End Function
>
> output:
>
> C:\wis\_vbs\0506\dev\forum
> cscript timsini.vbs
> [start]
> TIMS_0=1
> TIMS_1=0
> TIMS_2=1
> BOB=1
> BOB=12
>
> [start]
> TIMS_0=1
> TIMS_1=1
> TIMS_2=1
> BOB=1
> BOB=12
>
> ...
> cscript timsini.vbs
> [start]
> TIMS_0=1
> TIMS_1=1
> ...
>
> [start]
> TIMS_0=1
> TIMS_1=2
> ...
>
> ...
> cscript timsini.vbs
> [start]
> TIMS_0=1
> TIMS_1=8
>
> [start]
> TIMS_0=1
> TIMS_1=9
> ...
>
> cscript timsini.vbs
> [start]
> TIMS_0=1
> TIMS_1=9
> ...
>
> [start]
> TIMS_0=1
> TIMS_1=0
> ...

My System SpecsSystem Spec
Old 05-04-2009   #5 (permalink)
bob


 
 

Re: Incrementing number in INI file

of course now i have an additional question, i was trying to modify the
script so that it launches a file, but this keeps returning and error - any
guidance on why this fails

Option Explicit

Dim oFS : Set oFS = CreateObject( "Scripting.FileSystemObject" )
Dim oRE : Set oRE = New RegExp
Dim wshell : Set WshShell = WScript.CreateObject("WScript.Shell")
oRE.Multiline = True
oRE.Pattern = "^(TIMS_1=)(\d)(\s*)$"
Dim sTxt
sTxt = oFS.OpenTextFile( sFSpec ).ReadAll()
'WScript.Echo sTxt
sTxt = oRE.Replace( sTxt, GetRef( "replTims1" ) )
'WScript.Echo sTxt
oFS.CreateTextFile( sFSpec, True ).Write sTxt

Wshell.Run """c:\program files\connection manager.exe""", 1, false
WScript.Quit 0

Function replTims1( sMatch, sCapture0, sDigit, sCapture2, nPos, sSource )
Dim nDigit : nDigit = CByte( sDigit )
If nDigit = 9 Then
nDigit = 0
Else
nDigit = nDigit + 1
End If
replTims1 = sCapture0 & nDigit & sCapture2
End Function

"bob" <bob@xxxxxx> wrote in message
news:%23c1PqxNzJHA.1492@xxxxxx
Quote:

> my apologies for not being clear enough
>
> ekkehard, your assumption was correct, i wish to only increment the
> numerical value of TIMS_1, to change it to TIMS_1=1, TIMS_1=2 etc, what
> you did is perfect and exactly what i needed, i was striuggling with the
> extraction of the number sequence so you helped out miles
>
> bob
>
>
>
> "ekkehard.horner" <ekkehard.horner@xxxxxx> wrote in message
> news:49ff1935$0$31343$9b4e6d93@xxxxxx-online.net...
Quote:

>> bob schrieb:
Quote:

>>> hi,
>>> i have an ini file which i need to increment the numbers from 0-9 and
>>> then restart, so 0,1...8,9,0,1 etc for one of the lines.
>>>
>>> The file looks like this
>>> [start]
>>> TIMS_0=1
>>> TIMS_1=0
>>> TIMS_2=1
>>> BOB=1
>>> BOB=12
>>>
>>> i need to increment TIMS_1 by 1 (until it reaches 9 when the next number
>>> would be 0) each time the user starts the program
>>>
>>> i would really appreciate some help on this
>> [...]
>>
>> I second Pegasus' request for a more lucid specification. But if you want
>> to increment the TIMS_1 value (only), this will get you started:
>>
>> Option Explicit
>>
>> Dim sFSpec : sFSpec = ".\timsini.ini"
>> Dim oFS : Set oFS = CreateObject( "Scripting.FileSystemObject" )
>> Dim oRE : Set oRE = New RegExp
>> oRE.Multiline = True
>> oRE.Pattern = "^(TIMS_1=)(\d)(\s*)$"
>> Dim sTxt
>> sTxt = oFS.OpenTextFile( sFSpec ).ReadAll()
>> WScript.Echo sTxt
>> sTxt = oRE.Replace( sTxt, GetRef( "replTims1" ) )
>> WScript.Echo sTxt
>> oFS.CreateTextFile( sFSpec, True ).Write sTxt
>> WScript.Quit 0
>>
>> Function replTims1( sMatch, sCapture0, sDigit, sCapture2, nPos, sSource )
>> Dim nDigit : nDigit = CByte( sDigit )
>> If nDigit = 9 Then
>> nDigit = 0
>> Else
>> nDigit = nDigit + 1
>> End If
>> replTims1 = sCapture0 & nDigit & sCapture2
>> End Function
>>
>> output:
>>
>> C:\wis\_vbs\0506\dev\forum
>> cscript timsini.vbs
>> [start]
>> TIMS_0=1
>> TIMS_1=0
>> TIMS_2=1
>> BOB=1
>> BOB=12
>>
>> [start]
>> TIMS_0=1
>> TIMS_1=1
>> TIMS_2=1
>> BOB=1
>> BOB=12
>>
>> ...
>> cscript timsini.vbs
>> [start]
>> TIMS_0=1
>> TIMS_1=1
>> ...
>>
>> [start]
>> TIMS_0=1
>> TIMS_1=2
>> ...
>>
>> ...
>> cscript timsini.vbs
>> [start]
>> TIMS_0=1
>> TIMS_1=8
>>
>> [start]
>> TIMS_0=1
>> TIMS_1=9
>> ...
>>
>> cscript timsini.vbs
>> [start]
>> TIMS_0=1
>> TIMS_1=9
>> ...
>>
>> [start]
>> TIMS_0=1
>> TIMS_1=0
>> ...
>
>

My System SpecsSystem Spec
Old 05-04-2009   #6 (permalink)
ekkehard.horner


 
 

Re: Incrementing number in INI file

bob schrieb:
Quote:

> of course now i have an additional question, i was trying to modify the
> script so that it launches a file, but this keeps returning and error - any
> guidance on why this fails
>
> Option Explicit
>
line for sFSpec missing?
Quote:

> Dim oFS : Set oFS = CreateObject( "Scripting.FileSystemObject" )
> Dim oRE : Set oRE = New RegExp
> Dim wshell : Set WshShell = WScript.CreateObject("WScript.Shell")
wshell <> WshShell
Quote:

> oRE.Multiline = True
> oRE.Pattern = "^(TIMS_1=)(\d)(\s*)$"
> Dim sTxt
> sTxt = oFS.OpenTextFile( sFSpec ).ReadAll()
> 'WScript.Echo sTxt
> sTxt = oRE.Replace( sTxt, GetRef( "replTims1" ) )
> 'WScript.Echo sTxt
> oFS.CreateTextFile( sFSpec, True ).Write sTxt
>
> Wshell.Run """c:\program files\connection manager.exe""", 1, false
looks ok to me, but not tested
Quote:

> WScript.Quit 0
[...]

Again: please be more specific - that would help me/us to help you.

If you get an error you should post it:

C:[...]timsini2.vbs(5, 14) Laufzeitfehler in Microsoft VBScript:
Variable ist nicht definiert: 'WshShell'

My System SpecsSystem Spec
Old 05-04-2009   #7 (permalink)
bob


 
 

Re: Incrementing number in INI file

thanks ekkehard, as you pointed out it was a silly spelling error!!!


"ekkehard.horner" <ekkehard.horner@xxxxxx> wrote in message
news:49ff36fa$0$31869$9b4e6d93@xxxxxx-online.net...
Quote:

> bob schrieb:
Quote:

>> of course now i have an additional question, i was trying to modify the
>> script so that it launches a file, but this keeps returning and error -
>> any guidance on why this fails
>>
>> Option Explicit
>>
>
> line for sFSpec missing?
>
Quote:

>> Dim oFS : Set oFS = CreateObject( "Scripting.FileSystemObject" )
>> Dim oRE : Set oRE = New RegExp
>> Dim wshell : Set WshShell = WScript.CreateObject("WScript.Shell")
>
> wshell <> WshShell
>
Quote:

>> oRE.Multiline = True
>> oRE.Pattern = "^(TIMS_1=)(\d)(\s*)$"
>> Dim sTxt
>> sTxt = oFS.OpenTextFile( sFSpec ).ReadAll()
>> 'WScript.Echo sTxt
>> sTxt = oRE.Replace( sTxt, GetRef( "replTims1" ) )
>> 'WScript.Echo sTxt
>> oFS.CreateTextFile( sFSpec, True ).Write sTxt
>>
>> Wshell.Run """c:\program files\connection manager.exe""", 1, false
>
> looks ok to me, but not tested
>
Quote:

>> WScript.Quit 0
> [...]
>
> Again: please be more specific - that would help me/us to help you.
>
> If you get an error you should post it:
>
> C:[...]timsini2.vbs(5, 14) Laufzeitfehler in Microsoft VBScript:
> Variable ist nicht definiert: 'WshShell'
>

My System SpecsSystem Spec
Old 05-04-2009   #8 (permalink)
bob


 
 

Re: Incrementing number in INI file

i am trying to add in a second variable now, so when TIMS_1 cylces from 9 to
0, that the next items TIMS_2 changes one as well i,.e
TIMS1 = 9
TIMS2=1

run script
TIMS1=0
TIMS2=2

runscript
TIMS1=0
TIMS2=3

i can replicate the sections as you showed me, but i am struggling with how
to check to see if TIMS1 has become zero so that i can trigger the next
section


Option Explicit
Dim sFSpec : sFSpec = "c:\program files\ueconfiguration.ini"
Dim oFS : Set oFS = CreateObject( "Scripting.FileSystemObject" )
Dim oRE : Set oRE = New RegExp
Dim oRE2 : Set oRE2 = New RegExp
Dim wshell : Set Wshell = WScript.CreateObject("WScript.Shell")
Dim Bob

oRE.Multiline = True
oRE2.Multiline = True
oRE.Pattern = "^(TIMS_14=)(\d)(\s*)$"
oRE2.Pattern = "^(TIMS_13=)(\d)(\f*)$"
Dim sTxt
sTxt = oFS.OpenTextFile( sFSpec ).ReadAll()
sTxt = oRE.Replace( sTxt, GetRef( "replTims1" ) )

Bob=GetRef("replTims1") 'this is where i am struggling to test if
repltims1=0
If Bob=0 Then sTxt = oRE2.Replace( sTxt, GetRef( "replTims2" ) ) ' if zero
then i was triggering the next function
else end if

oFS.CreateTextFile( sFSpec, True ).Write sTxt
Wshell.Run """c:\program files\connection manager.exe""", 1, false
WScript.Quit 0

Function replTims1( sMatch, sCapture0, sDigit, sCapture2, nPos, sSource )
Dim nDigit : nDigit = CByte( sDigit )
If nDigit = 9 Then
nDigit = 0
Else
nDigit = nDigit + 1
End If
replTims1 = sCapture0 & nDigit & sCapture2
End Function

Function replTims2( fMatch, fCapture0, fDigit, fCapture2, nPos, fSource )
Dim nDigit : nDigit = CByte( fDigit )
If nDigit = 9 Then
nDigit = 0
Else
nDigit = nDigit + 1
End If
replTims2 = fCapture0 & nDigit & fCapture2
End Function


"bob" <bob@xxxxxx> wrote in message
news:efg5auOzJHA.3896@xxxxxx
Quote:

> thanks ekkehard, as you pointed out it was a silly spelling error!!!
>
>
> "ekkehard.horner" <ekkehard.horner@xxxxxx> wrote in message
> news:49ff36fa$0$31869$9b4e6d93@xxxxxx-online.net...
Quote:

>> bob schrieb:
Quote:

>>> of course now i have an additional question, i was trying to modify the
>>> script so that it launches a file, but this keeps returning and error -
>>> any guidance on why this fails
>>>
>>> Option Explicit
>>>
>>
>> line for sFSpec missing?
>>
Quote:

>>> Dim oFS : Set oFS = CreateObject( "Scripting.FileSystemObject" )
>>> Dim oRE : Set oRE = New RegExp
>>> Dim wshell : Set WshShell = WScript.CreateObject("WScript.Shell")
>>
>> wshell <> WshShell
>>
Quote:

>>> oRE.Multiline = True
>>> oRE.Pattern = "^(TIMS_1=)(\d)(\s*)$"
>>> Dim sTxt
>>> sTxt = oFS.OpenTextFile( sFSpec ).ReadAll()
>>> 'WScript.Echo sTxt
>>> sTxt = oRE.Replace( sTxt, GetRef( "replTims1" ) )
>>> 'WScript.Echo sTxt
>>> oFS.CreateTextFile( sFSpec, True ).Write sTxt
>>>
>>> Wshell.Run """c:\program files\connection manager.exe""", 1, false
>>
>> looks ok to me, but not tested
>>
Quote:

>>> WScript.Quit 0
>> [...]
>>
>> Again: please be more specific - that would help me/us to help you.
>>
>> If you get an error you should post it:
>>
>> C:[...]timsini2.vbs(5, 14) Laufzeitfehler in Microsoft VBScript:
>> Variable ist nicht definiert: 'WshShell'
>>
>
>

My System SpecsSystem Spec
Old 05-04-2009   #9 (permalink)
ekkehard.horner


 
 

Re: Incrementing number in INI file

I'm sorry, Bob, but I can't help you. Programming means to write code
to solve a problem. For that you have to understand the problem. I'm
willing to assume, that you do understand your problem, but I certainly
don't (see inline comments).

bob schrieb:
Quote:

> i am trying to add in a second variable now, so when TIMS_1 cylces from 9 to
TIMS_1 <> TIMS1 <> TIMS_14
Quote:

> 0, that the next items TIMS_2 changes one as well i,.e
> TIMS1 = 9
> TIMS2=1
>
> run script
> TIMS1=0
TIMS1 was 9, so it changes to 0 - ok
Quote:

> TIMS2=2
>
> runscript
> TIMS1=0
Why is TIMS1 = 0?
Quote:

> TIMS2=3
>
> i can replicate the sections as you showed me, but i am struggling with how
> to check to see if TIMS1 has become zero so that i can trigger the next
> section
Programming by copy and paste is doomed to fail, especially if you change
the problem to solve. In that case you have to start with a new plan (based
on the analysis of the problem) and to implement that.
Quote:

>
>
> Option Explicit
> Dim sFSpec : sFSpec = "c:\program files\ueconfiguration.ini"
> Dim oFS : Set oFS = CreateObject( "Scripting.FileSystemObject" )
> Dim oRE : Set oRE = New RegExp
> Dim oRE2 : Set oRE2 = New RegExp
> Dim wshell : Set Wshell = WScript.CreateObject("WScript.Shell")
> Dim Bob
>
> oRE.Multiline = True
> oRE2.Multiline = True
> oRE.Pattern = "^(TIMS_14=)(\d)(\s*)$"
> oRE2.Pattern = "^(TIMS_13=)(\d)(\f*)$"
------------------------------------^
QED: Programming by copy and paste is doomed to fail
Quote:

> Dim sTxt
> sTxt = oFS.OpenTextFile( sFSpec ).ReadAll()
> sTxt = oRE.Replace( sTxt, GetRef( "replTims1" ) )
>
> Bob=GetRef("replTims1") 'this is where i am struggling to test if
> repltims1=0
> If Bob=0 Then sTxt = oRE2.Replace( sTxt, GetRef( "replTims2" ) ) ' if zero
> then i was triggering the next function
> else end if
Did you look up the GetRef() function in the VBScript Docs? Do you
understand how a RegExp Replace function works? If not, why didn't you
ask?
Quote:

>
> oFS.CreateTextFile( sFSpec, True ).Write sTxt
> Wshell.Run """c:\program files\connection manager.exe""", 1, false
> WScript.Quit 0
>
> Function replTims1( sMatch, sCapture0, sDigit, sCapture2, nPos, sSource )
> Dim nDigit : nDigit = CByte( sDigit )
> If nDigit = 9 Then
> nDigit = 0
> Else
> nDigit = nDigit + 1
> End If
> replTims1 = sCapture0 & nDigit & sCapture2
> End Function
>
> Function replTims2( fMatch, fCapture0, fDigit, fCapture2, nPos, fSource )
> Dim nDigit : nDigit = CByte( fDigit )
> If nDigit = 9 Then
> nDigit = 0
> Else
> nDigit = nDigit + 1
> End If
> replTims2 = fCapture0 & nDigit & fCapture2
> End Function
[...]
My System SpecsSystem Spec
Old 05-05-2009   #10 (permalink)
ekkehard.horner


 
 

Re: Incrementing number in INI file

ekkehard.horner schrieb:
Quote:

> [...]
> bob schrieb:
Quote:

>> [...]
>> [I want to change values in an .ini file]
>>
> Programming by copy and paste is doomed to fail, especially if you change
> the problem to solve. In that case you have to start with a new plan (based
> on the analysis of the problem) and to implement that.
>
To illustrate:

First I understood your problem as "change (increment) one (possibly
more) values *independently*". That's why I came up with a RegExp Replace
Function that encapsulates the manipulation.

Function replTims1( sMatch, sCapture0, sDigit, sCapture2, nPos, sSource )
Dim nDigit : nDigit = CByte( sDigit )
If nDigit = 9 Then
nDigit = 0
Else
nDigit = nDigit + 1
End If
replTims1 = sCapture0 & nDigit & sCapture2
End Function

If you want to (meta) change the manipulation - let's say decrement the
value or replace it by some info from a database - all your changes
happen in that function. If you want to add the manipulation of another
..ini value, you add a function 'like this'. In both cases the main (top level)
code just has to identify the variable (pattern) and the manipulation
(GetRef( <function> )) and trigger the action:

sTxt = oRE.Replace( sTxt, GetRef( "replTims1" ) )
sTxt = oSomeOtherRe.Replace( sTxt, GetRef( "someOtherFunc" ) )

Your new specs indicate the problem now is "change one value *dependent"
on another value". This dependency has to be implemented in the main
code; perhaps like this:

Option Explicit

Dim sFSpec : sFSpec = ".\timsini.ini"
Dim oFS : Set oFS = CreateObject( "Scripting.FileSystemObject" )
Dim aTIMS : aTIMS = Array( "1", Empty, Empty, "2", Empty, Empty )
Dim oRE : Set oRE = New RegExp
oRE.Multiline = True
Dim sTxt : sTxt = oFS.OpenTextFile( sFSpec ).ReadAll()

Dim nTIM
For nTIM = 0 To UBound( aTIMS ) Step 3
oRE.Pattern = "^(TIMS_" & aTIMS( nTIM ) & "=)(\d)(\s*)$"
aTIMS( nTIM + 1 ) = CByte( oRE.Execute( sTxt )( 0 ).SubMatches( 1 ) )
Next
aTIMS( 2 ) = aTIMS( 1 ) + 1
If aTIMS( 2 ) >= 10 Then
aTIMS( 2 ) = 0
aTIMS( 5 ) = aTIMS( 4 ) + 1
Else
aTIMS( 5 ) = aTIMS( 4 )
End If
For nTIM = 0 To UBound( aTIMS ) Step 3
oRE.Pattern = "^(TIMS_" & aTIMS( nTIM ) & "=)(\d)(\s*)$"
sTxt = oRE.Replace( sTxt, "$1" & aTIMS( nTIM + 2 ) & "$3" )
Next
WScript.Echo Join( aTIMS, ", " )
oFS.CreateTextFile( sFSpec, True ).Write sTxt
WScript.Quit 0

Now finding the (old) value(s), changing them, and replacing them are
distributed over the main code - that's the price you pay for the dependency.
Doing something similiar to another pair of values will add considerably to
the complexity of the code. That there is something fishy with this code
can be seen by the fact that it violates the "DRY: Don't repeat yourself"
rule:

oRE.Pattern = "^(TIMS_" & aTIMS( nTIM ) & "=)(\d)(\s*)$"

occurs twice. [BTW: Can you improve the code regarding this aspect?]
My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
Search number of file which match a pattern PowerShell
The best way to get number of string occurrences in a binary file PowerShell
get the number of lines in a text file PowerShell
Maximum number of characters in file name extension Vista General
Count the number of Columns/rows in a CSV file.... PowerShell


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46