Can anyone help me with this simple code?

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
paul.darsey
Posts: 20
Joined: 30 May 2011 18:44

Can anyone help me with this simple code?

#1 Post by paul.darsey » 30 May 2011 18:48

@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

nitt
Posts: 218
Joined: 22 Apr 2011 02:43

Re: Can anyone help me with this simple code?

#2 Post by nitt » 30 May 2011 18:59

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

paul.darsey
Posts: 20
Joined: 30 May 2011 18:44

Re: Can anyone help me with this simple code?

#3 Post by paul.darsey » 30 May 2011 19:01

what was I doing wrong?

nitt
Posts: 218
Joined: 22 Apr 2011 02:43

Re: Can anyone help me with this simple code?

#4 Post by nitt » 30 May 2011 19:06

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.

paul.darsey
Posts: 20
Joined: 30 May 2011 18:44

Re: Can anyone help me with this simple code?

#5 Post by paul.darsey » 30 May 2011 19:13

Thanks, i just started really getting into programming with batch. Thanks for the help.

nitt
Posts: 218
Joined: 22 Apr 2011 02:43

Re: Can anyone help me with this simple code?

#6 Post by nitt » 30 May 2011 19:14

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.

paul.darsey
Posts: 20
Joined: 30 May 2011 18:44

Re: Can anyone help me with this simple code?

#7 Post by paul.darsey » 30 May 2011 19:43

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

Post Reply