>
> "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
>
>
>