Werbung: SecurityConsole.de verwaltet Ihre Computer mit Security Essentails aus der Cloud!
30 Tage kostenfrei testen und 20% Rabatt für Ihre Bestellung mit Promocode: WBF2685582
(Promocode gültig bis 31.12.2011)

Group:  English: Windows Server » microsoft.public.windows.server.scripting
Thread: reading a "counter" file and incrementing based on # in file.

HTVi
TV Discussion Newsgroups

reading a "counter" file and incrementing based on # in file.
mjm 5/1/2007 8:51:02 PM
I would like to have a script open a file (the file will only have a single
number in it). If it sees a 1 or 2 it should increment the number by 1 - a 1
becomes a 2 2 becomes a 3. If it sees a 3 it should reset to 0.
Any help would be greatly appreciated.


Re: reading a "counter" file and incrementing based on # in file.
Tom Lavedas <tglbatch[ at ]cox.net> 5/1/2007 9:03:57 PM
On May 1, 4:51 pm, mjm <m...[ at ]discussions.microsoft.com> wrote:
[Quoted Text]
> I would like to have a script open a file (the file will only have a single
> number in it). If it sees a 1 or 2 it should increment the number by 1 - a 1
> becomes a 2 2 becomes a 3. If it sees a 3 it should reset to 0.
> Any help would be greatly appreciated.

Try something like this ...

' note: this is untested. Use at you own risk
sFilename = "X:\Somewhere\somename.txt"
set fso = createobject("scripting.filesystemobject")
n = cSng(fso.opentextfile(sFilename , 1).readall)
if n < 3 then
n = n+1
else
n = 0
end if
fso.opentextfile(sFilename , 2, true).write n

Tom Lavedas
==========
http://members.cox.net/tglbatch/wsh/

Re: reading a "counter" file and incrementing based on # in file.
"Al Dunbar" <AlanDrub[ at ]hotmail.com.nospaam> 5/2/2007 2:00:42 AM

"Tom Lavedas" <tglbatch[ at ]cox.net> wrote in message
news:1178053437.089123.221050[ at ]c35g2000hsg.googlegroups.com...
[Quoted Text]
> On May 1, 4:51 pm, mjm <m...[ at ]discussions.microsoft.com> wrote:
>> I would like to have a script open a file (the file will only have a
>> single
>> number in it). If it sees a 1 or 2 it should increment the number by 1 -
>> a 1
>> becomes a 2 2 becomes a 3. If it sees a 3 it should reset to 0.
>> Any help would be greatly appreciated.
>
> Try something like this ...
>
> ' note: this is untested. Use at you own risk
> sFilename = "X:\Somewhere\somename.txt"
> set fso = createobject("scripting.filesystemobject")
> n = cSng(fso.opentextfile(sFilename , 1).readall)
> if n < 3 then
> n = n+1
> else
> n = 0
> end if
> fso.opentextfile(sFilename , 2, true).write n

My preference would be:

n = n + 1
if n > 3 then
n = 0
end if

but both our solutions, as well as the statement of the problem, fail to
recognize the possibility of the number being either less than 1 or greater
than 3. If zero should be incremented to 1, that is what our solutions do,
but perhaps it is supposed to stay at zero. Same if the number is already
greater than 3, it will keep incrementing forever.

/Al


Re: reading a "counter" file and incrementing based on # in file.
Tom Lavedas <tglbatch[ at ]cox.net> 5/2/2007 12:45:35 PM
On May 1, 10:00 pm, "Al Dunbar" <AlanD...[ at ]hotmail.com.nospaam> wrote:
[Quoted Text]
> "Tom Lavedas" <tglba...[ at ]cox.net> wrote in message
>
> news:1178053437.089123.221050[ at ]c35g2000hsg.googlegroups.com...
>
>
>
> > On May 1, 4:51 pm, mjm <m...[ at ]discussions.microsoft.com> wrote:
> >> I would like to have a script open a file (the file will only have a
> >> single
> >> number in it). If it sees a 1 or 2 it should increment the number by 1 -
> >> a 1
> >> becomes a 2 2 becomes a 3. If it sees a 3 it should reset to 0.
> >> Any help would be greatly appreciated.
>
> > Try something like this ...
>
> > ' note: this is untested. Use at you own risk
> > sFilename = "X:\Somewhere\somename.txt"
> > set fso = createobject("scripting.filesystemobject")
> > n = cSng(fso.opentextfile(sFilename , 1).readall)
> > if n < 3 then
> > n = n+1
> > else
> > n = 0
> > end if
> > fso.opentextfile(sFilename , 2, true).write n
>
> My preference would be:
>
> n = n + 1
> if n > 3 then
> n = 0
> end if
>
> but both our solutions, as well as the statement of the problem, fail to
> recognize the possibility of the number being either less than 1 or greater
> than 3. If zero should be incremented to 1, that is what our solutions do,
> but perhaps it is supposed to stay at zero. Same if the number is already
> greater than 3, it will keep incrementing forever.
>
> /Al

I don't believe your last statement is true: "Same if the number is
already greater than 3, it will keep incrementing forever."

I specifically set the test to handle >3, but assumed it should be
reset. Your solution does the same, I believe.

Neither of our approaches address numbers less than zero, as you
stated.

The other problem I recognized and chose not to address is if the file
contains non-numeric data. General error handling just seemed to be
outside of the scope of the request.

Tom Lavedas
============
http://members.cox.net/tglbatch/wsh/

Re: reading a "counter" file and incrementing based on # in file.
neothwin 5/5/2007 5:09:00 AM


"Tom Lavedas" wrote:

[Quoted Text]
> On May 1, 10:00 pm, "Al Dunbar" <AlanD...[ at ]hotmail.com.nospaam> wrote:
> > "Tom Lavedas" <tglba...[ at ]cox.net> wrote in message
> >
> > news:1178053437.089123.221050[ at ]c35g2000hsg.googlegroups.com...
> >
> >
> >
> > > On May 1, 4:51 pm, mjm <m...[ at ]discussions.microsoft.com> wrote:
> > >> I would like to have a script open a file (the file will only have a
> > >> single
> > >> number in it). If it sees a 1 or 2 it should increment the number by 1 -
> > >> a 1
> > >> becomes a 2 2 becomes a 3. If it sees a 3 it should reset to 0.
> > >> Any help would be greatly appreciated.
> >
> > > Try something like this ...
> >
> > > ' note: this is untested. Use at you own risk
> > > sFilename = "X:\Somewhere\somename.txt"
> > > set fso = createobject("scripting.filesystemobject")
> > > n = cSng(fso.opentextfile(sFilename , 1).readall)
> > > if n < 3 then
> > > n = n+1
> > > else
> > > n = 0
> > > end if
> > > fso.opentextfile(sFilename , 2, true).write n
> >
> > My preference would be:
> >
> > n = n + 1
> > if n > 3 then
> > n = 0
> > end if
> >
> > but both our solutions, as well as the statement of the problem, fail to
> > recognize the possibility of the number being either less than 1 or greater
> > than 3. If zero should be incremented to 1, that is what our solutions do,
> > but perhaps it is supposed to stay at zero. Same if the number is already
> > greater than 3, it will keep incrementing forever.
> >
> > /Al
>
> I don't believe your last statement is true: "Same if the number is
> already greater than 3, it will keep incrementing forever."
>
> I specifically set the test to handle >3, but assumed it should be
> reset. Your solution does the same, I believe.
>
> Neither of our approaches address numbers less than zero, as you
> stated.
>
> The other problem I recognized and chose not to address is if the file
> contains non-numeric data. General error handling just seemed to be
> outside of the scope of the request.
>
> Tom Lavedas
> ============
> http://members.cox.net/tglbatch/wsh/
>
>
n=(n+1) mod 4
Re: reading a "counter" file and incrementing based on # in file.
"Al Dunbar" <AlanDrub[ at ]hotmail.com.nospaam> 5/5/2007 1:44:27 PM

"neothwin" <neothwin[ at ]discussions.microsoft.com> wrote in message
news:60DFC600-C6A3-44DF-AE02-1B6B6F3F29F1[ at ]microsoft.com...
[Quoted Text]
>
>
> "Tom Lavedas" wrote:
>
>> On May 1, 10:00 pm, "Al Dunbar" <AlanD...[ at ]hotmail.com.nospaam> wrote:
>> > "Tom Lavedas" <tglba...[ at ]cox.net> wrote in message
>> >
>> > news:1178053437.089123.221050[ at ]c35g2000hsg.googlegroups.com...
>> >
>> >
>> >
>> > > On May 1, 4:51 pm, mjm <m...[ at ]discussions.microsoft.com> wrote:
>> > >> I would like to have a script open a file (the file will only have a
>> > >> single
>> > >> number in it). If it sees a 1 or 2 it should increment the number
>> > >> by 1 -
>> > >> a 1
>> > >> becomes a 2 2 becomes a 3. If it sees a 3 it should reset to 0.
>> > >> Any help would be greatly appreciated.
>> >
>> > > Try something like this ...
>> >
>> > > ' note: this is untested. Use at you own risk
>> > > sFilename = "X:\Somewhere\somename.txt"
>> > > set fso = createobject("scripting.filesystemobject")
>> > > n = cSng(fso.opentextfile(sFilename , 1).readall)
>> > > if n < 3 then
>> > > n = n+1
>> > > else
>> > > n = 0
>> > > end if
>> > > fso.opentextfile(sFilename , 2, true).write n
>> >
>> > My preference would be:
>> >
>> > n = n + 1
>> > if n > 3 then
>> > n = 0
>> > end if
>> >
>> > but both our solutions, as well as the statement of the problem, fail
>> > to
>> > recognize the possibility of the number being either less than 1 or
>> > greater
>> > than 3. If zero should be incremented to 1, that is what our solutions
>> > do,
>> > but perhaps it is supposed to stay at zero. Same if the number is
>> > already
>> > greater than 3, it will keep incrementing forever.
>> >
>> > /Al
>>
>> I don't believe your last statement is true: "Same if the number is
>> already greater than 3, it will keep incrementing forever."
>>
>> I specifically set the test to handle >3, but assumed it should be
>> reset. Your solution does the same, I believe.
>>
>> Neither of our approaches address numbers less than zero, as you
>> stated.
>>
>> The other problem I recognized and chose not to address is if the file
>> contains non-numeric data. General error handling just seemed to be
>> outside of the scope of the request.
>>
>> Tom Lavedas
>> ============
>> http://members.cox.net/tglbatch/wsh/
>>
>>
> n=(n+1) mod 4

1 becomes 2 - OK
2 becomes 3 - OK
3 becomes 0 - OK
but he did not say that 0 should become 1.

/Al


Re: reading a "counter" file and incrementing based on # in file.
neothwin 5/6/2007 12:48:01 PM


"Al Dunbar" wrote:

[Quoted Text]
>
> "neothwin" <neothwin[ at ]discussions.microsoft.com> wrote in message
> news:60DFC600-C6A3-44DF-AE02-1B6B6F3F29F1[ at ]microsoft.com...
> >
> >
> > "Tom Lavedas" wrote:
> >
> >> On May 1, 10:00 pm, "Al Dunbar" <AlanD...[ at ]hotmail.com.nospaam> wrote:
> >> > "Tom Lavedas" <tglba...[ at ]cox.net> wrote in message
> >> >
> >> > news:1178053437.089123.221050[ at ]c35g2000hsg.googlegroups.com...
> >> >
> >> >
> >> >
> >> > > On May 1, 4:51 pm, mjm <m...[ at ]discussions.microsoft.com> wrote:
> >> > >> I would like to have a script open a file (the file will only have a
> >> > >> single
> >> > >> number in it). If it sees a 1 or 2 it should increment the number
> >> > >> by 1 -
> >> > >> a 1
> >> > >> becomes a 2 2 becomes a 3. If it sees a 3 it should reset to 0.
> >> > >> Any help would be greatly appreciated.
> >> >
> >> > > Try something like this ...
> >> >
> >> > > ' note: this is untested. Use at you own risk
> >> > > sFilename = "X:\Somewhere\somename.txt"
> >> > > set fso = createobject("scripting.filesystemobject")
> >> > > n = cSng(fso.opentextfile(sFilename , 1).readall)
> >> > > if n < 3 then
> >> > > n = n+1
> >> > > else
> >> > > n = 0
> >> > > end if
> >> > > fso.opentextfile(sFilename , 2, true).write n
> >> >
> >> > My preference would be:
> >> >
> >> > n = n + 1
> >> > if n > 3 then
> >> > n = 0
> >> > end if
> >> >
> >> > but both our solutions, as well as the statement of the problem, fail
> >> > to
> >> > recognize the possibility of the number being either less than 1 or
> >> > greater
> >> > than 3. If zero should be incremented to 1, that is what our solutions
> >> > do,
> >> > but perhaps it is supposed to stay at zero. Same if the number is
> >> > already
> >> > greater than 3, it will keep incrementing forever.
> >> >
> >> > /Al
> >>
> >> I don't believe your last statement is true: "Same if the number is
> >> already greater than 3, it will keep incrementing forever."
> >>
> >> I specifically set the test to handle >3, but assumed it should be
> >> reset. Your solution does the same, I believe.
> >>
> >> Neither of our approaches address numbers less than zero, as you
> >> stated.
> >>
> >> The other problem I recognized and chose not to address is if the file
> >> contains non-numeric data. General error handling just seemed to be
> >> outside of the scope of the request.
> >>
> >> Tom Lavedas
> >> ============
> >> http://members.cox.net/tglbatch/wsh/
> >>
> >>
> > n=(n+1) mod 4
>
> 1 becomes 2 - OK
> 2 becomes 3 - OK
> 3 becomes 0 - OK
> but he did not say that 0 should become 1.
>
> /Al
>
>
>

ok

n=((n + 1) Mod 4) * -(n <> 0)

regards,

Home | Search | Terms | Imprint Contact
Newsgroups Reader - provided by WiredBox.Net
Suche nach Orten, Städten, Postleitzahlen, Vorwahlen, Kfz-Kennzeichen