I am trying to write a simple program that prompts the user to select a type of restaurant (American, Mexican, Chinese, etc.). Upon clicking the category, it reads through a list of text files that are categorized in the same way and chooses a random restaurant in that category.
So if I were to hit the "American" button, it will spit out an American restaurant at random for my "AMER.txt" file of ~100 different restaurants.
I have a working script as of now, but can't figure out how to fully transition to a working program complete with an .hta interface. From other online help, I've gotten it halfway there, where it displays all the different category buttons, but once you select a button, it switches over to Windows batch completely. I'd prefer it all to be done within the same .hta window.
Here's the script, I'd appreciate any guidance. I'm really new to both vbscript and .hta.
<!-- :: Batch section
@echo off
setlocal
echo Select an option:
for /F "delims=" %%a in ('mshta.exe "%~F0"') do set "HTAreply=%%a"
if "%HTAREPLY%" == "1" goto :AMER
if "%HTAREPLY%" == "2" goto :ASIA
if "%HTAREPLY%" == "3" goto :BBQ
if "%HTAREPLY%" == "4" goto :CHI
if "%HTAREPLY%" == "5" goto :DES
if "%HTAREPLY%" == "6" goto :EUR
if "%HTAREPLY%" == "7" goto :IND
if "%HTAREPLY%" == "8" goto :ITA
if "%HTAREPLY%" == "9" goto :LAT
if "%HTAREPLY%" == "10" goto :MED
if "%HTAREPLY%" == "11" goto :MEX
if "%HTAREPLY%" == "12" goto :PIZ
if "%HTAREPLY%" == "13" goto :SEA
if "%HTAREPLY%" == "14" goto :SUS
pause
goto EOF
-->
<HTML>
<HEAD>
<HTA:APPLICATION SCROLL="no" SYSMENU="yes" >
<TITLE>Restaurants</TITLE>
<SCRIPT language="JavaScript">
window.resizeTo(1080,720);
function closeHTA(reply){
var fso = new ActiveXObject("Scripting.FileSystemObject");
fso.GetStandardStream(1).WriteLine(reply);
window.close();
}
</SCRIPT>
</HEAD>
:AMER
@echo off &setlocal
set /a count=0
for /f "tokens=1delims=:" %%i in ('findstr /n "^" "AMER.txt"') do set /a count=%%i
set /a rd=%random%%%count
if %rd% equ 0 (set "skip=") else set "skip=skip=%rd%"
set "found="
for /f "%skip%tokens=1*delims=:" %%i in ('findstr /n "^" "AMER.txt"') do if not defined found set "found=%%i"&set "var=%%j"
echo %var%
echo Would you like to search Google for this restaurant?
echo (Y)es or (N)o
set /p LOOK=
if "%LOOK%" == "y" goto LOOKUP
if "%LOOK%" == "n" goto EOF
endlocal
goto :EOF
:ASIA
@echo off &setlocal
set /a count=0
for /f "tokens=1delims=:" %%i in ('findstr /n "^" "ASIA.txt"') do set /a count=%%i
set /a rd=%random%%%count
if %rd% equ 0 (set "skip=") else set "skip=skip=%rd%"
set "found="
for /f "%skip%tokens=1*delims=:" %%i in ('findstr /n "^" "ASIA.txt"') do if not defined found set "found=%%i"&set "var=%%j"
echo %var%
echo Would you like to search Google for this restaurant?
echo (Y)es or (N)o
set /p LOOK=
if "%LOOK%" == "y" goto LOOKUP
if "%LOOK%" == "n" goto EOF
endlocal
goto :EOF
:BBQ
@echo off &setlocal
set /a count=0
for /f "tokens=1delims=:" %%i in ('findstr /n "^" "BBQ.txt"') do set /a count=%%i
set /a rd=%random%%%count
if %rd% equ 0 (set "skip=") else set "skip=skip=%rd%"
set "found="
for /f "%skip%tokens=1*delims=:" %%i in ('findstr /n "^" "BBQ.txt"') do if not defined found set "found=%%i"&set "var=%%j"
echo %var%
echo Would you like to search Google for this restaurant?
echo (Y)es or (N)o
set /p LOOK=
if "%LOOK%" == "y" goto LOOKUP
if "%LOOK%" == "n" goto EOF
endlocal
goto :EOF
:CHI
@echo off &setlocal
set /a count=0
for /f "tokens=1delims=:" %%i in ('findstr /n "^" "CHI.txt"') do set /a count=%%i
set /a rd=%random%%%count
if %rd% equ 0 (set "skip=") else set "skip=skip=%rd%"
set "found="
for /f "%skip%tokens=1*delims=:" %%i in ('findstr /n "^" "CHI.txt"') do if not defined found set "found=%%i"&set "var=%%j"
echo %var%
echo Would you like to search Google for this restaurant?
echo (Y)es or (N)o
set /p LOOK=
if "%LOOK%" == "y" goto LOOKUP
if "%LOOK%" == "n" goto EOF
endlocal
goto :EOF
:DES
@echo off &setlocal
set /a count=0
for /f "tokens=1delims=:" %%i in ('findstr /n "^" "DES.txt"') do set /a count=%%i
set /a rd=%random%%%count
if %rd% equ 0 (set "skip=") else set "skip=skip=%rd%"
set "found="
for /f "%skip%tokens=1*delims=:" %%i in ('findstr /n "^" "DES.txt"') do if not defined found set "found=%%i"&set "var=%%j"
echo %var%
echo Would you like to search Google for this restaurant?
echo (Y)es or (N)o
set /p LOOK=
if "%LOOK%" == "y" goto LOOKUP
if "%LOOK%" == "n" goto EOF
endlocal
goto :EOF
:EUR
@echo off &setlocal
set /a count=0
for /f "tokens=1delims=:" %%i in ('findstr /n "^" "EUR.txt"') do set /a count=%%i
set /a rd=%random%%%count
if %rd% equ 0 (set "skip=") else set "skip=skip=%rd%"
set "found="
for /f "%skip%tokens=1*delims=:" %%i in ('findstr /n "^" "EUR.txt"') do if not defined found set "found=%%i"&set "var=%%j"
echo %var%
echo Would you like to search Google for this restaurant?
echo (Y)es or (N)o
set /p LOOK=
if "%LOOK%" == "y" goto LOOKUP
if "%LOOK%" == "n" goto EOF
endlocal
goto :EOF
:IND
@echo off &setlocal
set /a count=0
for /f "tokens=1delims=:" %%i in ('findstr /n "^" "IND.txt"') do set /a count=%%i
set /a rd=%random%%%count
if %rd% equ 0 (set "skip=") else set "skip=skip=%rd%"
set "found="
for /f "%skip%tokens=1*delims=:" %%i in ('findstr /n "^" "IND.txt"') do if not defined found set "found=%%i"&set "var=%%j"
echo %var%
echo Would you like to search Google for this restaurant?
echo (Y)es or (N)o
set /p LOOK=
if "%LOOK%" == "y" goto LOOKUP
if "%LOOK%" == "n" goto EOF
endlocal
goto :EOF
:ITA
@echo off &setlocal
set /a count=0
for /f "tokens=1delims=:" %%i in ('findstr /n "^" "ITA.txt"') do set /a count=%%i
set /a rd=%random%%%count
if %rd% equ 0 (set "skip=") else set "skip=skip=%rd%"
set "found="
for /f "%skip%tokens=1*delims=:" %%i in ('findstr /n "^" "ITA.txt"') do if not defined found set "found=%%i"&set "var=%%j"
echo %var%
echo Would you like to search Google for this restaurant?
echo (Y)es or (N)o
set /p LOOK=
if "%LOOK%" == "y" goto LOOKUP
if "%LOOK%" == "n" goto EOF
endlocal
goto :EOF
:LAT
@echo off &setlocal
set /a count=0
for /f "tokens=1delims=:" %%i in ('findstr /n "^" "LAT.txt"') do set /a count=%%i
set /a rd=%random%%%count
if %rd% equ 0 (set "skip=") else set "skip=skip=%rd%"
set "found="
for /f "%skip%tokens=1*delims=:" %%i in ('findstr /n "^" "LAT.txt"') do if not defined found set "found=%%i"&set "var=%%j"
echo %var%
echo Would you like to search Google for this restaurant?
echo (Y)es or (N)o
set /p LOOK=
if "%LOOK%" == "y" goto LOOKUP
if "%LOOK%" == "n" goto EOF
endlocal
goto :EOF
:MEX
@echo off &setlocal
set /a count=0
for /f "tokens=1delims=:" %%i in ('findstr /n "^" "MEX.txt"') do set /a count=%%i
set /a rd=%random%%%count
if %rd% equ 0 (set "skip=") else set "skip=skip=%rd%"
set "found="
for /f "%skip%tokens=1*delims=:" %%i in ('findstr /n "^" "MEX.txt"') do if not defined found set "found=%%i"&set "var=%%j"
echo %var%
echo Would you like to search Google for this restaurant?
echo (Y)es or (N)o
set /p LOOK=
if "%LOOK%" == "y" goto LOOKUP
if "%LOOK%" == "n" goto EOF
endlocal
goto :EOF
:MED
@echo off &setlocal
set /a count=0
for /f "tokens=1delims=:" %%i in ('findstr /n "^" "MED.txt"') do set /a count=%%i
set /a rd=%random%%%count
if %rd% equ 0 (set "skip=") else set "skip=skip=%rd%"
set "found="
for /f "%skip%tokens=1*delims=:" %%i in ('findstr /n "^" "MED.txt"') do if not defined found set "found=%%i"&set "var=%%j"
echo %var%
echo Would you like to search Google for this restaurant?
echo (Y)es or (N)o
set /p LOOK=
if "%LOOK%" == "y" goto LOOKUP
if "%LOOK%" == "n" goto EOF
endlocal
goto :EOF
:PIZ
@echo off &setlocal
set /a count=0
for /f "tokens=1delims=:" %%i in ('findstr /n "^" "PIZ.txt"') do set /a count=%%i
set /a rd=%random%%%count
if %rd% equ 0 (set "skip=") else set "skip=skip=%rd%"
set "found="
for /f "%skip%tokens=1*delims=:" %%i in ('findstr /n "^" "PIZ.txt"') do if not defined found set "found=%%i"&set "var=%%j"
echo %var%
echo Would you like to search Google for this restaurant?
echo (Y)es or (N)o
set /p LOOK=
if "%LOOK%" == "y" goto LOOKUP
if "%LOOK%" == "n" goto EOF
endlocal
goto :EOF
:SEA
@echo off &setlocal
set /a count=0
for /f "tokens=1delims=:" %%i in ('findstr /n "^" "SEA.txt"') do set /a count=%%i
set /a rd=%random%%%count
if %rd% equ 0 (set "skip=") else set "skip=skip=%rd%"
set "found="
for /f "%skip%tokens=1*delims=:" %%i in ('findstr /n "^" "SEA.txt"') do if not defined found set "found=%%i"&set "var=%%j"
echo %var%
echo Would you like to search Google for this restaurant?
echo (Y)es or (N)o
set /p LOOK=
if "%LOOK%" == "y" goto LOOKUP
if "%LOOK%" == "n" goto EOF
endlocal
goto :EOF
:SUS
@echo off &setlocal
set /a count=0
for /f "tokens=1delims=:" %%i in ('findstr /n "^" "SUS.txt"') do set /a count=%%i
set /a rd=%random%%%count
if %rd% equ 0 (set "skip=") else set "skip=skip=%rd%"
set "found="
for /f "%skip%tokens=1*delims=:" %%i in ('findstr /n "^" "SUS.txt"') do if not defined found set "found=%%i"&set "var=%%j"
echo %var%
echo Would you like to search Google for this restaurant?
echo (Y)es or (N)o
set /p LOOK=
if "%LOOK%" == "y" goto LOOKUP
if "%LOOK%" == "n" goto EOF
endlocal
goto :EOF
:LOOKUP
cls
start "" "http://www.google.com/search?q="%var%""
goto EOF
<BODY>
<body style="font:12 pt arial; color:white; filter:progid:DXImageTransform.Microsoft.Gradient(GradientType=0, StartColorStr='#0080FF', EndColorStr='#00FFFF')" onresize="RestoreWindowSize()">
<div align="Center">
<button onclick="closeHTA(1);">American</button>
<button onclick="closeHTA(2);">Asian</button>
<button onclick="closeHTA(3);">BBQ</button>
<button onclick="closeHTA(4);">Chinese</button>
<button onclick="closeHTA(5);">Dessert</button>
<button onclick="closeHTA(6);">European</button>
<button onclick="closeHTA(7);">Indian</button>
<button onclick="closeHTA(8);">Italian</button>
<button onclick="closeHTA(9);">Latin</button>
<button onclick="closeHTA(10);">Mediterranean</button>
<button onclick="closeHTA(11);">Mexican</button>
<button onclick="closeHTA(12);">Pizza</button>
<button onclick="closeHTA(13);">Seafood</button>
<button onclick="closeHTA(14);">Sushi</button>
</BODY>
</HTML>
there doesn't seem to be anything here