@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
Can anyone help me with this simple code?
Moderator: DosItHelp
Re: Can anyone help me with this simple code?
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
-
- Posts: 20
- Joined: 30 May 2011 18:44
Re: Can anyone help me with this simple code?
what was I doing wrong?
Re: Can anyone help me with this simple code?
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.
-
- Posts: 20
- Joined: 30 May 2011 18:44
Re: Can anyone help me with this simple code?
Thanks, i just started really getting into programming with batch. Thanks for the help.
Re: Can anyone help me with this simple code?
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.
-
- Posts: 20
- Joined: 30 May 2011 18:44
Re: Can anyone help me with this simple code?
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
@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
cls
start %browser% http://www.google.com
goto exit
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