Page 1 of 1

Can anyone help me with this simple code?

Posted: 30 May 2011 18:48
by paul.darsey
@ECHO Off
color FC
:choice
cls
echo Google = g
echo Facebook = f
echo Gmail = m
echo.
set /p choice = "Hello, %username%, what would you like to do?"
if %choice% == g goto google
if %choice% == f goto Facebook
if %choice% == m goto Gmail
if %choice% == G goto Google
if %choice% == F goto Facebook
if %choice% == M goto Gmail
else goto errorchoice
:google
cls
@ECHO
start iexplore.exe "google url"
goto exit
:Facebook
cls
@Echo
start iexplore.exe "facebook url"
goto exit
:Gmail
cls
@Echo
start iexplore.exe "gmail url"
goto exit
:errorchoice
set /p error = "hey you entered a wrong choice!!"
pause
goto choose
:exit
cls
exit

Re: Can anyone help me with this simple code?

Posted: 30 May 2011 18:59
by nitt
fixed

Code: Select all

@echo Off
color FC
:choice
cls
echo Google = g
echo Facebook = f
echo Gmail = m
echo.
set /p choice="Hello, %username%, what would you like to do?"
if "%choice%"=="g" goto google
if "%choice%"=="f" goto Facebook
if "%choice%"=="m" goto Gmail
if "%choice%"=="G" goto Google
if "%choice%"=="F" goto Facebook
if "%choice%"=="M" goto Gmail
goto errorchoice
:google
cls
start iexplore.exe "google url"
goto exit
:Facebook
cls
start iexplore.exe "facebook url"
goto exit
:Gmail
cls
start iexplore.exe "gmail url"
goto exit
:errorchoice
set /p error="hey you entered a wrong choice!!"
pause
goto choice
:exit
cls
exit

Re: Can anyone help me with this simple code?

Posted: 30 May 2011 19:01
by paul.darsey
what was I doing wrong?

Re: Can anyone help me with this simple code?

Posted: 30 May 2011 19:06
by nitt
paul.darsey wrote:what was I doing wrong?


Code: Select all

@echo Off
color FC
:choice
cls
echo Google = g
echo Facebook = f
echo Gmail = m
echo.
set /p choice="Hello, %username%, what would you like to do?"
if "%choice%"=="g" (cls & start iexplore.exe "gmail url" & exit)
if "%choice%"=="f" (cls & start iexplore.exe "gmail url" & exit)
if "%choice%"=="m" (cls & start iexplore.exe "gmail url" & exit)
if "%choice%"=="G" (cls & start iexplore.exe "gmail url" & exit)
if "%choice%"=="F" (cls & start iexplore.exe "gmail url" & exit)
if "%choice%"=="M" (cls & start iexplore.exe "gmail url" & exit)
echo hey you entered a wrong choice!!
pause
goto choice


That's a shorter version.

You did a few things wrong. Like instead of "goto choice" you wrote "goto choice". And you usually compare things in quotes like

"%var%"=="asdf"

and it's not " == " it's "==".

Just look through it, it's just simple things.

Also, instead of putting "@echo" everywhere, just put one "@echo off" at the top.

Re: Can anyone help me with this simple code?

Posted: 30 May 2011 19:13
by paul.darsey
Thanks, i just started really getting into programming with batch. Thanks for the help.

Re: Can anyone help me with this simple code?

Posted: 30 May 2011 19:14
by nitt
paul.darsey wrote:Thanks, i just started really getting into programming with batch. Thanks for the help.


You're welcome. :3

Batch is a really fun language to work with. If you want anymore help, just post here. I will be glad to help. And some of our other users, too.

Re: Can anyone help me with this simple code?

Posted: 30 May 2011 19:43
by paul.darsey
why doesnt this work


@echo Off
color FC
:chooseBrowswer
echo Firefox = f
echo Internet Explorer = i
echo Googel Chrome = g
set /p browser ="Hey, %username% choose a browser."
if "%browser%" == "f" goto firefox
if "%browser%" == "i" goto internetexplorer
if "%browser%" == "g" goto googlechrome
:firefox
%browser% = "firefox.exe"
goto choice
:internetexplorer
%browser% = "iexplore.exe"
goto choice
:googlechrome
%broswer% = "chrome.exe"
goto choice
:choice
cls
echo Google = g
echo Facebook = f
echo Gmail = m
echo Statebank = s
echo.
set /p choice="Hello, %username%, what would you like to do?"
if "%choice%"=="g" goto google
if "%choice%"=="f" goto Facebook
if "%choice%"=="m" goto Gmail
if "%choice%"== "s" goto StateBank
if "%choice%"=="G" goto Google
if "%choice%"=="F" goto Facebook
if "%choice%"=="M" goto Gmail
if "%choice%"=="S" goto StateBank
goto errorchoice
:google
cls
start %browser% http://www.google.com
goto exit
:Facebook
cls
start %browser% url
goto exit
:Gmail
cls
start %browser% url
goto exit
:StateBank
cls
start %browser% url
goto exit
:errorchoice
cls
echo %choice% is not a valid option!
ping -n 5 127.0.0.1 >nul
goto choice
:exit
cls
exit