Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
Hey,
I've been trying for ages but I cant seem to
make my batch script auto-capitalize the first
letter of user input.I was thinking of something along the lines of
::Batch Start@ECHO OFF
COLOR F2
CLSCLS
set /p name=What Is Your First Name? :
set name=%name%set name=%n%:~0,1%
set name=%ame%:2~%ECHO.%n%%ame%
PAUSE
::Batch End
But this does nothing.
I need to be able to make %n% capital then
somehow do the sum%n%+%ame%=%name%
so that i can use the command
if "%name%"=="Tom" GOTO EX
This will be used multiple times for different
names to redirect to different places.It is so that people dont have to type Tom to
go to the right place they just have to type
tom.Of cource there are ways to do this such as
if "%name%"=="Tom" GOTO EX
if "%name%"=="tom" GOTO EXbut then the command i use in the end:
ECHO.First Name : %name%
would display tom and look unprofessional.
I am reasonably new to batch programing so if
anyone could please give me an example or
two on how to do it it would be much
appreciated.Thanks,
LEoH

why don't you use languages like vbscript, which makes life easier for you?
Set objArgs = WScript.Arguments theStr = objArgs(0) WScript.Echo Ucase(Left(theStr,1)) & Mid(theStr,2)
save the above as test.vbs and on command lineC:\test>cscript /nologo test.vbs "thestring" Thestring

Here is something that should also do the trick:
for %%a in (A B C D E F G H I J K L M N O P Q R S T U V W X Y Z) do call set n=%%n:%%a=%%a%%

Ok, thanks.
I dont fully understand how to use the script.
I need it to work with the currant directory. I dont have the
cscript thing (like i said, im only knew. I dont understand what
it is, is it an include?)
I need all of the required files in the same folder or a subfolder
so that it can easily be run off a USB on another computer.The reason i dont use vbscript is because of how much more
dificult it is than batch.I am only new to programming and BATCH is by far the
easiest programing language i have ever even looked at.My knowledge of VBSCRIPT is small... Incredibly small... I
have been looking for a place to learn it since before i started
BATCH.If anyone knows of an easy place to start with VBS please
help me.Thanks,
LEoH

Response to Judago:
Looks just like what im after but...
Like i said, im new to programming in general and have only
just recently started learning batch.could you please explain how to add it to:
@ECHO OFF
set /p name=What Is Your First Name? :
set name=%name%
CLS
set /p lname=What Is Your Last Name? :
set lname=%lname%
CLS
set /p gen=What Is Your Gender? (M/F) :
set gen=%gen%
CLS::The name corrector thing needs to be added before this
::comment.ECHO.Please Wait...
ping www.google.com >nul
CLS
ECHO._____________________________________________
__________ >>%name%_%lname%_Fortune.txt
ECHO. >>%name%_%lname%_Fortune.txt
ECHO.%Name% >>%name%_%lname%_Fortune.txt
ECHO._____________________________________________
__________ >>%name%_%lname%_Fortune.txt
ECHO. >>%n%name%_%lname%_Fortune.txt
if "%name%"=="Alexander" GOTO AL
if "%name%"=="Lewis" GOTO LE
if "%name%"=="Brandon" GOTO AL
if "%name%"=="Aidan" GOTO AL
if "%name%"=="Samuel" GOTO AL
if "%name%"=="Daniel" GOTO AL
if "%name%"=="Tom" GOTO EX
IF "%name%"=="Jayden" GOTO JAYDEN
if "%name%"=="Connor" GOTO CONNOR
if "%name%"=="Dylan" GOTO UN
if "%name%"=="Jett" GOTO UN
if "%gen%"=="M" GOTO M
if "%gen%"=="F" GOTO FThanks,
LEoHEDIT: just so there are no complaints. The names are added before the gender thing so that if the names are on the list they are directed to were they are meant to go... if that makes sense... the genders are for peoples names who aren't listed.

Ok I only just realised that you don't really want to capitalise so much as do a case insensitive string comparision. If has this built in, the /i switch makes it a case insensitive comparison:
if /i "%name%"=="Alexander" GOTO AL
As for the other thing:
set /p name=What Is Your First Name? : set n=%name:~0,1% for %%a in (A B C D E F G H I J K L M N O P Q R S T U V W X Y Z) do call set n=%%n:%%a=%%a%% set name=%n%%name:~1%

Awesome. Thanks.
Works perfectly.
The only problem is it now generates a random file.
Its not much of a problem, I just add a delete command in the
script and it goes.(Sorry. This probably seems like its going forever.) Is it
possible to make the first letter after a - in a name turn capital
also? (Your probably thinking "Selfish b---tard. Never happy.")
What i mean is, say the name was Smith-Anderson, can you
make it, not only change the s in Smith to capital but also the
a in Anderson.
Thanks, Its just that one of the last names of the people who
is going to be using this has a hyphen in it.eg.
smith-anderson = Smith-Anderson
johnson-calculus = Johnson-Calculus(Needs to work with any hyphened name, if not don't worie
about it.)Thanks again.
LEoHps.
Yes, i knew about the /i switch but that doesn't change the T
in Tom to capital when it prints the name in the end.

You can break the name up with a for loop then set two variables from it, then perform the same procedure as above on each variable:
for /f "tokens=1,2 delims=-" %%a in (%name%) do ( set given=%%a set sur=%%b )

thanks,
One MAJOR problem.
I have no idea how to add them.
I tried this:
::_____________________________________________
@ECHO OFF
COLOR F2
CLS
set /p name=What Is Your First Name? :
set n=%name:~0,1%
for %%a in (A B C D E F G H I J K L M N O P Q R S T U V
W X Y Z) do call set n=%%n:%%a=%%a%%
set name=%n%%name:~1%CLS
set /p lname=What Is Your Last Name? :
for /f "tokens=1,2 delims=-" %%a in (%lname%) do (
set pa=%%a
set pb=%%b
)
set n=%pa:~0,1%
for %%a in (A B C D E F G H I J K L M N O P Q R S T U V
W X Y Z) do call set n=%%n:%%a=%%a%%
set parta=%n%%pa:~1%
set n=%pb:~0,1%
for %%a in (A B C D E F G H I J K L M N O P Q R S T U V
W X Y Z) do call set n=%%n:%%a=%%a%%
set partb=%n%%pb:~1%
set lname=%parta%-%partb%
CLS
set /p gen=What Is Your Gender? (M/F) :
set n=%gen:~0,1%
for %%a in (A B C D E F G H I J K L M N O P Q R S T U V
W X Y Z) do call set n=%%n:%%a=%%a%%
set gen=%n%%gen:~1%
CLS:loop
set num=%random%
if /i %num% GTR 2 goto loop
if /i %num% LSS 1 goto loopif "%name%"=="Tom" GOTO EX
if "%gen%"=="M" GOTO %num%
if "%gen%"=="F" GOTO F:EX
ECHO.First Name : %name%
ECHO.Last Name : %lname%PAUSE
::(This is just the neccicary parts of the script, I removed M
::and F and the rest of the names because it would be to long,
::i also shortened EX)
::________________________________________________
But of course, like everything else i do, this doesn't work.It prints an error like "System cannot locate the file (then the
hyphened name)" Which doesn't make sense.
And when you ECHO the last name it sais something like
~0,1~1-~0,1~1 which completely confuses me. I just found
out it even turns un-hyphened last names (eg. Howard) into
the same thing...
It needs to have the last name set as lname.
Thanks for your help but how do i include this into my script?(ps. I am going to implement this into visual studio 6.0's vb and make it a bit
more visual. I am making a credits section, is it ok if i add
your name (Judago) into it?

A common technique in handling input is to make it case insensitive, either all upper or all lower case. The test string is also set correspondingly.

Yes, i knew about the /i switch but that doesn't change
the T
in Tom to capital when it prints the name in the end.I posted that a bit further up.
But thanks anyways.

"System cannot locate the file (then the
hyphened name)"Sorry this is my fault - it should be
for /f "tokens=1,2 delims=-" %%a in ("%lname%") do (I missed out the double quotes.....
As for credits, you can if you want but I'm not picky.

You really are awesome.
Thankyou so much for your help.Hopefully this is the last question i have.
Is it possible to test if the name has a hyphen before it
completes the command.
Because it is making normal last names say eg. Smith~0,1
which looks a bit stupid.Thanks again,
LEoHEDIT:
btw, Thanks, i will add you to credits.

I given the script a once over just to show you how you can bring down the script into something a little smaller.
There are a couple of things you may want to have a look into though.
1. You may want to consider doing a couple of check on your variables from the set /p commands, some people insist on entering symbols with special meanings <,>,|, & ^.
2. What if the user types their name in caps?
::_____________________________________________ @ECHO OFF COLOR F2 CLS set /p name=What Is Your First Name? : set fn=%name:~0,1% CLS set /p lname=What Is Your Last Name? : for /f "tokens=1,2 delims=-" %%a in ("%lname%") do ( set lname=%%a set pblname=%%b ) set ln=%lname:~0,1% if defined pblname set pb=%lname:~0,1% CLS set /p gen=What Is Your Gender? (M/F) : set gn=%gen:~0,1% for %%a in (A B C D E F G H I J K L M N O P Q R S T U V W X Y Z) do ( call set fn=%%fn:%%a=%%a%% call set ln=%%ln:%%a=%%a%% call set gn=%%gn:%%a=%%a%% if defined pb call set pb=%%pb:%%a=%%a%% ) set name=%fn%%name:~1% if not defined pb (set lname=%ln%%lname:~1%) else set lname=%ln%%lname:~1%-%pb%%pblname:~1% set gen=%gn%%gen:~1% CLS

Your the best.
Thankyou so much for your help.
I think thats the end of my long list of questions.One of your lines of code is:
if defined pblname set pb=%lname:~0,1%
Which turns the first letter of the second part to the same as
the first but i fixed that by changing it to:
if defined pblname set pb=%pblname:~0,1%Thanks again for all your help.
LEoH.EDIT:
Well. I guess if the user types their name in caps i'm screwed. No idea what to do there... reverse your code and add it again? ill give that a shot.

Haha!
Did it!
I turned them lowercase.
for %%a in (a b c d e f g h i j k l m n o p q r s t u v w x y
z) do (
call set name=%%name:%%a=%%a%%
call set lname=%%lname:%%a=%%a%%
)
Thanks for the idea.
I'm not sure what you mean by symbols though. Why would
someone put a ^ in their name?Anyways. The script now does what i want it to.
Thanks again,
LEoH

I'm not sure what you mean by symbols though. Why would
someone put a ^ in their name?Sometimes it can be malicious intent, sometimes it can be a typo and often a way to spice up that boring old name.
The good example is & which is a command separator. Using a non-dynamic(%var%) will cause everything after the & as another command. Try this with the script, comment out all of the cls statements, start the script and type in name&netstat an then fill in the rest of the prompts. This will work for just about any command available; del *? format /y d:?
I normally use something along the lines of:
for %%a in ("&" ">" "<" "|" "^") do call set "enter=%%enter:%%~a=%%"to strip them out. Setlocal enabledelayedexpansion can alse be of some help here, but I will leave you to do the web searching.

Thanks, Cant believe i didn't know that you could do that.
I don't really think it neccisary to have your name set as |ÊW!
§' or Å•|•Ê•X•ĕѕЕʕ®.
And like you said. It might screw around with the script.I was wondering. Is it possible to have a progress bar whilst it
calculates the random number?
I was thinking something along the lines of:
SET IN=.
:loop
ECHO.%in%
set in=%in%.
set num=%random%
if /i %num% GTR 2 goto loop
if /i %num% LSS 1 goto loopBut this just prints 9874*878387 dots on the screen which
makes it kinda pointless.I tried google-ing it but all i could find was one that was only
compatible with DOS and of course i'm not running DOS.And another thing:
Can you make the thing scan to see if a file already exists for
a person?
Along with the:
:EX
ECHO.First Name : %name%
ECHO.Last Name : %lname%
There is also a
:EX
ECHO.First Name : %name%
>>%name%_%lname%_Fortune.txt
ECHO.Last Name : %lname%
>>%name%_%lname%_Fortune.txt
Which is made in the directory reports using:
DIR Reports >nul
IF ERRORLEVEL 1 MKDIR Reports
CLS
MOVE %name%_%lname%.txt Reports
del *.txt *.log /fI tried using:
DIR Reports >nul
IF ERRORLEVEL 1 goto loop
DIR %name%_%lname%.txt >nul
IF ERRORLEVEL 1 goto loop
TYPE %name%_%lname%.txtSo that the random number part of it does not always
generate a new random file but i want it to look like it is by
still taking time.
The problem i am having with this small script is that it prints
"File Not Found" to the screen if it isn't there...(The .log file is a time logger that tells you how long it took to
calculate the random number.)Sorry. More questions.
LEoH

If has built in functionality to test for the existence of files and directories:
if exist "whatever" do somethingThis will check to see if a file or folder exist, it is exactly the same for both as windows won't allow a file and folder of the same name exist in the same directory.
if /i %num% GTR 2 goto loop if /i %num% LSS 1 goto loopThis puzzles me, how random can %num% really be? If you just trying time how long it takes for one to be returned by %random% it may be difficult to add a progress bar as it will be difficult to tell how many iterations it will take and thus know how far to progress the bar each time.

I guess it probably would be a bit hard without knowing how many attempts it will take.
What:
if /i %num% GTR 2 goto loop
if /i %num% LSS 1 goto loop
Is for is:
It keeps calculating random numbers until you eventually get a 1 or a 2 and then if you are a male (%gen%=M) it performs the command:
if "%gen%"=="M" GOTO %num%
(This is not actually part of my script but... for eg.)
:loop
if /i %num% GTR 2 goto loop
if /i %num% LSS 1 goto loopGOTO %num%
:1
ECHO.Hello
ECHO.I like Fish
PAUSE
EXIT:2
ECHO.Hello.
ECHO.I like Pork.
PAUSE
EXIT
Thats pretty much all its good for.
I was hoping to add more than one of them to my script but for some reason when there are two it exits... Doesn't matter.But if it is possible - Even some sort of timed progress bar that doesn't finish until the random number has finished generating would do. However it wouldn't be able to show as something like 10% of the bar if it finished... if that makes sense.

There are much faster ways to get your random number:
One way that is probably the fastest and most accurate way would be to know that %random% generates a number between 0 and 32767 and change the if statements acordingly.
if %random% lss 16384 (do or set one thing) else do or set the other
This should be so much faster that a progress bar will be superfluous.You can also use substrings, although the results may sometimes be a little skewd; for a one digit result you could use:
set num=%random:~-1%

I don't think you understand.
I tried
"if "%gen%"=="M" if %random% lss 9000 (goto 1) else
goto 2"
But what didn't work. It looks kind of wrong.
I need it to have an equal chance of 1 or 2.Also. I edited the above post like 10 times.
Sorry if i'm being a bit annoying and thanks for your help.
LEoH
EDIT:
Also, I have no idea how to use "if exists" in the script.
I tried
if exist "Reports" MOVE %name%_%lname%_Fortune.txt Reports (else mkdir reports)
if exist %name%_%lname%_Fortune.txt MOVE %name%_%lname%_Fortune.txt Reports MKDIR Reports
Along with a few other things and none worked...

If you use 16384 you will have an equal chance, because, as I stated, %random% returns a number 0 - 32767. For our purposes consider it 1 - 32768 (so it is easer to do math on):
32768 / 2 = 16384
I must be either "less than" or "greater than or equal to" this number because of the number has been cycled up one.
The only thing I can see wrong with the statement above is that there shouldn't be a linebreak after else (it's not just wrapping, copying the line into a text editor shows the linebreak), but that could be caused by the forums.

Your edit, you have the syntax of the if statements wrong:
if exist "file" command
if exist "file" (command) else command
if exist "file" (
command
) else (
command
)All of this is available from interactive help, start a cmd window(start>run>cmd) and type in "command /?"(i.e. if /?) to get quick help.
A really convenient way to view the help is by running this script it will generate a html file with most commands listed.
if exist "Reports" (MOVE %name%_%lname%_Fortune.txt Reports) else mkdir reports

Awesome. Thanks.
I used:
if exist "Reports" (
Move %name%_%lname%_Fortune.txt Reports
) else (
MKDIR Reports&Move %name%_%lname%_Fortune.txt
Reports
)
CLSAnd that did just what it was meant to.
I also used:
if "%gen%"=="M" GOTO rd:rd
if %random% lss 16384 (GOTO 1) else (GOTO 2)
But i'm not sure if this works. It always seems to be showing
up with goto 2... after about 30 attempts i haven't got
one 1...
And when i change it to if %random% lss 16384 GOTO 1
else (GOTO 2)It always shows with 1...

Unless you have a messed up %random% variable or have set to it(it's no such a good idea to set to a system variable) in the current session I can't see why except for it being random. It's certainly working on my end.
When you say goto 2 is always showing up, do you have echo enabled or disabled(i.e do you have echo off somewhere at the start of the script). If echo is on (code blocks) which are contained inside brackets will always show up but won't always execute.

Echo is off.
@ECHO OFF
Setlocal enabledelayedexpansion
COLOR F2
SET stt=%time%
CLS
^^^^^^^^^^^^^^^^
Thats the beginning of the script.
Could it be the Setlocal enabledelayedexpansion?
I wasn't completely sure what you meant by that so I added it.
I thought maybe it wouldn't hurt but maybe it did?EDIT: Apart from that there is no chance that it is being messed up because its the first time the variable is in the script, and the last.
LEoH

Unless you are using variables marked with ! (!var!) you don't need the setlocal enabledelayedexpansion, nor will it be the cause. My guess is that the random number just isn't playing nice and predictable, or predictably random(it is pseudo random anyway).
Give it a few more trys and if it doesn't work for you post the whole script. I won't be able to have a look at it until tormorrow though anyway.

Ok, Thanks.
I will give it a shot and look through further myself (just to
make sure) then ill get back to you.Thanks again for all your help,
LEoH

Ok.
I give up.
And I have to go...
Here is the script.
I had to edit it a little as not to provide 'Personal Information'
about people on the internet - Not sure if they would be all to
happy.
It has the basic concept it just doesent have all the
redirections in place.
__________________________________________________::Fortune Teller
::CREDITS:
:: LEoH - Main Script
:: Judago - Capitalization & General Help
:: (Probably half the main script)
:: lee123abc - Timer@ECHO OFF
COLOR F2
SET stt=%time%
CLSCLS
ECHO.Fortune Teller
ECHO.By LEoH
ECHO.
ECHO.
PING 127.0.0.1 >nulCLS
set /p name=What Is Your First Name? :
for %%a in ("&" ">" "<" "|" "^") do call set "name=%%name:%%~a=%%"
set fn=%name:~0,1%
CLS
set /p lname=What Is Your Last Name? :
for %%a in ("&" ">" "<" "|" "^") do call set "lname=%%lname:%%~a=%%"
for /f "tokens=1,2 delims=-" %%a in ("%lname%") do (
set lname=%%a
set pblname=%%b
)
set ln=%lname:~0,1%
if defined pblname set pb=%pblname:~0,1%
CLS
set /p gen=What Is Your Gender? (M/F) :
for %%a in ("&" ">" "<" "|" "^") do call set "gen=%%gen:%%~a=%%"
set gn=%gen:~0,1%for %%a in (a b c d e f g h i j k l m n o p q r s t u v w x y z) do (
call set name=%%name:%%a=%%a%%
call set lname=%%lname:%%a=%%a%%
)for %%a in (A B C D E F G H I J K L M N O P Q R S T U V W X Y Z) do (
call set fn=%%fn:%%a=%%a%%
call set ln=%%ln:%%a=%%a%%
call set gn=%%gn:%%a=%%a%%
if defined pb call set pb=%%pb:%%a=%%a%%
)set name=%fn%%name:~1%
if not defined pb (set lname=%ln%%lname:~1%) else set lname=%ln%%lname:~1%-%pb%%pblname:~1%
set gen=%gn%%gen:~1%
CLSset fullname=%name% %lname%
ECHO.Generating Report For %fullname%...
echo %time%>>timelog.log:cont
CLS
ECHO._______________________________________________________
ECHO.
ECHO.%Name%
ECHO._______________________________________________________
ECHO._______________________________________________________ >>%name%_%lname%_Fortune.txt
ECHO. >>%name%_%lname%_Fortune.txt
ECHO.%fullname% >>%name%_%lname%_Fortune.txt
ECHO._______________________________________________________ >>%name%_%lname%_Fortune.txt
ECHO. >>%n%name%_%lname%_Fortune.txt
if "%fullname%"=="Alexander" GOTO AL
if "%name%"=="Lewis" GOTO LE
if "%name%"=="Tom" GOTO rd
if "%gen%"=="M" GOTO rd
if "%gen%"=="F" GOTO F:rd
if %random% gtr 16384 (
GOTO 1
) else (
GOTO 2
):1
echo %time%>>timelog.log
set ett=%time%
CLS
ECHO.First Name : %name%
ECHO.Last Name : %lname%
ECHO.Gender : %gen%
ECHO.
ECHO.First Name : %name% >>%name%_%lname%_Fortune.txt
ECHO.Last Name : %lname% >>%name%_%lname%_Fortune.txt
ECHO.Gender : %gen% >>%name%_%lname%_Fortune.txt
ECHO. >>%name%_%lname%_Fortune.txt
ECHO.
PAUSE
GOTO END:2
echo %time%>>timelog.log
set ett=%time%
CLS
ECHO.First Name : %name%
ECHO.Last Name : %lname%
ECHO.Gender : %gen%
ECHO.
ECHO.First Name : %name% >>%name%_%lname%_Fortune.txt
ECHO.Last Name : %lname% >>%name%_%lname%_Fortune.txt
ECHO.Gender : %gen% >>%name%_%lname%_Fortune.txt
ECHO. >>%name%_%lname%_Fortune.txt
ECHO.
PAUSE
GOTO END:F
echo %time%>>timelog.log
set ett=%time%
CLS
ECHO.First Name : %name%
ECHO.Last Name : %lname%
ECHO.Gender : %gen%
ECHO.
ECHO.First Name : %name% >>%name%_%lname%_Fortune.txt
ECHO.Last Name : %lname% >>%name%_%lname%_Fortune.txt
ECHO.Gender : %gen% >>%name%_%lname%_Fortune.txt
ECHO. >>%name%_%lname%_Fortune.txt
ECHO.
PAUSE
GOTO END:AL
echo %time%>>timelog.log
set ett=%time%
CLS
ECHO.First Name : %name%
ECHO.Last Name : %lname%
ECHO.Gender : %gen%
ECHO.
ECHO.First Name : %name% >>%name%_%lname%_Fortune.txt
ECHO.Last Name : %lname% >>%name%_%lname%_Fortune.txt
ECHO.Gender : %gen% >>%name%_%lname%_Fortune.txt
ECHO. >>%name%_%lname%_Fortune.txt
ECHO.
PAUSE
GOTO END:LE
echo %time%>>timelog.log
set ett=%time%
CLS
ECHO.First Name : %name%
ECHO.Last Name : %lname%
ECHO.Gender : %gen%
ECHO.
ECHO.First Name : %name% >>%name%_%lname%_Fortune.txt
ECHO.Last Name : %lname% >>%name%_%lname%_Fortune.txt
ECHO.Gender : %gen% >>%name%_%lname%_Fortune.txt
ECHO. >>%name%_%lname%_Fortune.txt
ECHO.
PAUSE
GOTO END:EX
echo %time%>>timelog.log
set ett=%time%
CLS
ECHO.First Name : %name%
ECHO.Last Name : %lname%
ECHO.Gender : %gen%
ECHO.
ECHO.First Name : %name% >>%name%_%lname%_Fortune.txt
ECHO.Last Name : %lname% >>%name%_%lname%_Fortune.txt
ECHO.Gender : %gen% >>%name%_%lname%_Fortune.txt
ECHO. >>%name%_%lname%_Fortune.txt
ECHO.
PAUSE
GOTO END
:END::-------TIME MATHS-------
:TIME_MATHS
::set information into variables
setlocal enabledelayedexpansion
for /f %%j in (timelog.log) do (
set /a number +=1
set reaction_time=%%j
set reaction!number!=!reaction_time!
)
::=========================================
::sort variables into specific variables
set hh1=%reaction1:~0,2%
set mm1=%reaction1:~3,2%
set ss1=%reaction1:~6,2%
set hh2=%reaction2:~0,2%
set mm2=%reaction2:~3,2%
set ss2=%reaction2:~6,2%
::=========================================
::this is an important step. the reason you add 2 is to get
::away from the 08 and 09 octal which will crash your file.
set /a hh1 +=2
set /a hh2 +=2
set /a mm1 +=2
set /a mm2 +=2
set /a ss1 +=2
set /a ss2 +=2
::=========================================
::a bit of maths to get varibales correct for time
::sort out seconds
:GET_SS
set /a answer_ss = %ss2%-%ss1%
if %answer_ss% == 0 goto :GET_MM
if %answer_ss% lss 0 (
goto :SS_NEGATIVE
) else (
goto :GET_MM
)
:SS_NEGATIVE
set answer_ss=
set /a ss2 +=60
set /a answer_ss = %ss2%-%ss1%
set /a mm2 -=1
::=========================================
::sort out minutes
:GET_MM
set /a answer_mm=%mm2%-%mm1%
if %answer_mm% == 0 goto :GET_HH
if %answer_mm% lss 0 (
goto :MM_NEGATIVE
) else (
set /a answer_mm = 60*%answer_mm%
goto :GET_HH
)
:MM_NEGATIVE
set answer_mm=
set /a mm2 +=60
set /a answer_mm = %mm2%-%mm1%
set /a hh2 -=1
::=========================================
::sort out hours
:GET_HH
set /a answer_hh = %hh2%-%hh1%
if %answer_hh% == 0 goto :FINAL_ANSWER
if %answer_hh% lss 0 (
goto :HH_NEGATIVE
) else (
set /a answer_hh = 60*60*%answer_hh%
goto :FINAL_ANSWER
)
:HH_NEGATIVE
set answer_hh=
set /a hh2 +=60
set /a answer_hh = %hh2%-%hh1%
::=========================================
::final answer should display in combined seconds
:FINAL_ANSWER
set /a final_time = %answer_hh%+%answer_mm%+%answer_ss%
ECHO._______________________________________________________ >>%name%_%lname%_Fortune.txt
ECHO. >>%name%_%lname%_Fortune.txt
ECHO.Start Time : %stt% >>%name%_%lname%_Fortune.txt
ECHO.End Time : %ett% >>%name%_%lname%_Fortune.txt
ECHO.Time To Compile : %final_time% >>%name%_%lname%_Fortune.txt
ECHO._______________________________________________________ >>%name%_%lname%_Fortune.txt
ECHO. >>%name%_%lname%_Fortune.txt
ECHO. >>%name%_%lname%_Fortune.txt
ECHO. >>%name%_%lname%_Fortune.txt
ECHO. >>%name%_%lname%_Fortune.txt
if exist "Reports" (
Move %name%_%lname%_Fortune.txt Reports
) else (
MKDIR Reports&Move %name%_%lname%_Fortune.txt Reports
)
CLS
del *.txt *.log /f
EXIT__________________________________________________
Another reason i took some redirections out is because it
saves about 40 lines.Thankyou,
LEoH
EDIT: I just noticed. I do have variables set with !. They are in lee123abc's timer.
EDIT2: NOTE: If you copy this directly into notepad it doesn't work. It separates the outputs away from some of the ECHO.s.
Just check, It's pretty obvious which ones.

Hi there.
You should notice the 'setlocal enabledelayedexpansion'When you use this you have to use '!example!' instead of '%example%'.
If you want to learn about this, type setlocal /? at the command prompt.Good luck

This is actually quite troublesome, you fortune teller is quite good a predicting pseudo random numbers!
Here is a quick snapshoot of the first random numbers generated after the :rd label:
24804 25199 25196 25190 25186 25180 25177 25173 25170 25167 25164 25160 25157 25154 25150 25147 25147 25137Scary, no?
My only suggestion would be to use:
if %random:~-2% lss 50 (What I did to get this result was run the script once for each number listed, the first random number in the script and after the rd label.

Reply to lee123abc:
Ok, thanks.
So does that mean i should change all my variables to ! rather
than &?Reply to Judago:
Wow.
Yes, Very scary. Ill try your line. See if that fits.
Thanks,LEoH
EDIT: Thanks Judago.
The Line worked. It no longer only selects certain numbers.

![]() |
Copy files to folders wit...
|
dynamic dns updation
|

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |