Page 1 of 1
Help
Posted: 18 Apr 2010 10:19
by 1+2=46
Hi.
I am making a batch file where it's purpose will be understood whenever you see the code.
Ok, here's the code:
Code: Select all
@echo off
Cls
Title
Cls
Set RS=1000
:Loop
Color 0C
Ping localhost -n 1 -w 1000 >nul
Set /A R=%random%%%999+1
Set /A a=%R%
If %a% LSS 50 (
If %a% LSS 25 (
Goto Loop
)
If %R%==%RS% (
Goto Loop
)
Cls
Color 0A
Echo %R% is not greater than 50 and is not less than 25.
Echo -%R%->>%HomePath%\Desktop\Numbers.txt
Set RS=%R%
Ping localhost -n 3 -w 1000 >nul
Cls
Goto Loop
)
If %R% LSS 100 set sentence=%R% is greater than 50.
If %R% GTR 100 set sentence=%R% is greater than 50.
If %a% GTR 10 (
If %R% GTR 50 (
If %R% LSS 100 (
Set sentence=%R% is greater than 50.
)
If %R% GTR 100 (
Set sentence=%R% is greater than 50.
)
If %R% LSS 25 (
Set sentence=%R% is less than 25.
)
Echo %sentence%
Goto Loop
)
Goto Loop
For some reason the code doesn't works.
And by the way, the code is all made by me.
Re: Help
Posted: 18 Apr 2010 21:48
by DosItHelp
The brackets are not balanced, a closing bracket missing somewhere near the end.
Another thing I noticed is that the "If %R%==%RS%" condition will never be true because R will will be 0<R<1000, but never 1000, because "%random% %% 999" will return a random number 0<=number<999.
DosItHelp?
Re: Help
Posted: 19 Apr 2010 06:51
by 1+2=46
DosItHelp wrote:The brackets are not balanced, a closing bracket missing somewhere near the end.
Another thing I noticed is that the "If %R%==%RS%" condition will never be true because R will will be 0<R<1000, but never 1000, because "%random% %% 999" will return a random number 0<=number<999.
DosItHelp?
No. If you pay attention you'll see that every time a number between 50 and 25 is picked up, a command is wrote like this: "Set RS=%R%". I made it like that, so the next number will never be the same as the past one.
And thank you. I just noticed the missing closing bracket. It was really the last one.
Re: Help
Posted: 19 Apr 2010 16:23
by 1+2=46
Okay, I modified the code so it works more perfectly.
But when I run the file I get a error.
Here it goes the new modified code:
Code: Select all
@echo off
Cls
Title
Cls
Set number=0
Set RS=1000
If not exist "%HomePath%\Desktop\Numbers.txt" (
Echo Numbers between 175 and 200:>>"%HomePath%\Desktop\Numbers.txt"
Echo.>>"%HomePath%\Desktop\Numbers.txt"
Ping localhost -n 1 -w 1000 >nul
)
:Loop
Color 0C
Ping localhost -n 1 -w 1000 >nul
Set /A R=%random%%%999+1
Set /A a=%R%
If %a% LSS 200 (
If %a% LSS 175 (
Goto Loop
)
If %R%==%RS% (
Goto Loop
)
Cls
Color 0A
If %b%==%0% (
Goto Loop
)
If %b%==%1% (
Goto Loop
)
If %b%==%2% (
Goto Loop
)
If %b%==%3% (
Goto Loop
)
If %b%==%4% (
Goto Loop
)
If %b%==%5% (
Goto Loop
)
If %b%==%6% (
Goto Loop
)
If %b%==%7% (
Goto Loop
)
If %b%==%8% (
Goto Loop
)
If %b%==%9% (
Goto Loop
)
If %b%==%10% (
Goto Loop
)
If %b%==%11% (
Goto Loop
)
If %b%==%12% (
Goto Loop
)
If %b%==%13% (
Goto Loop
)
If %b%==%14% (
Goto Loop
)
If %b%==%15% (
Goto Loop
)
If %b%==%16% (
Goto Loop
)
If %b%==%17% (
Goto Loop
)
If %b%==%18% (
Goto Loop
)
If %b%==%19% (
Goto Loop
)
If %b%==%20% (
Goto Loop
)
If %b%==%21% (
Goto Loop
)
If %b%==%22% (
Goto Loop
)
If %b%==%23% (
Goto Loop
)
If %b%==%24% (
Goto Loop
)
If %b%==%25% (
Goto Loop
)
Set number=%number% + 1
Set b=%number%
If %number%% GEQ 25 (
Goto Loop
)
Echo %R% is not greater than 200 and is not less than 175.
Echo -%R%->>%HomePath%\Desktop\Numbers.txt
Set RS=%R%
Ping localhost -n 3 -w 1000 >nul
Cls
Goto Loop
)
If %R% LSS 100 set sentence=%R% is less than 200.
If %R% GTR 100 set sentence=%R% is greater than 200.
If %a% GTR 10 (
If %R% GTR 200 (
If %R% LSS 200 (
Set sentence=%R% is greater than 200.
)
If %R% GTR 100 (
Set sentence=%R% is greater than 200.
)
If %R% LSS 175 (
Set sentence=%R% is less than 175.
)
Echo %sentence%
Goto Loop
)
)
Goto Loop
Could someone help me, please?
Re: Help
Posted: 21 Apr 2010 11:46
by 1+2=46
No one?
Re: Help
Posted: 22 Apr 2010 00:03
by jeb
Hi 1+2=46,
will always fail, because it expands to
Because at first %b% is empty, %0 expands to the name of your batch file and the second % will be ignored.
I suppose that is not exactly what you want
You should use some echo's for debugging, than you can find this types of bugs
jeb
Re: Help
Posted: 22 Apr 2010 07:20
by 1+2=46
jeb wrote:Hi 1+2=46,
will always fail, because it expands to
Because at first %b% is empty, %0 expands to the name of your batch file and the second % will be ignored.
I suppose that is not exactly what you want
You should use some echo's for debugging, than you can find this types of bugs
jeb
I tried:
(at the start of the code)
And still doesn't works.
Re: Help
Posted: 22 Apr 2010 10:51
by jeb
Hi,
as I wrote, your code will always fail
Code: Select all
If %b%==%0% (
Goto Loop
)
If %b%==%1% (
Goto Loop
)
If %b%==%2% (
Goto Loop
)
You should try to debug it with some echo lines, like
echo %b% == %0%
to see why it will fail
jeb
Re: Help
Posted: 03 May 2010 09:01
by avery_larry
Can't use 0 - 9 as the variables because they expand as the command line arguments:
%0% will expand to just %0
%1% will expand to just %1
...
If you MUST use the numbers as the variables, you will have to use delayedexpansion and !0! !1! etc. Haven't found any other way to do it.