简体   繁体   中英

Trying to make a telefphonebook in batchscript Win8

I'm a beginner to batchscripting and I'm trying to make a telephoneregister that prints all, adds, deletes and searches for phonenumbers, but I can't get it to work correctly and I'm wondering where I did go wrong. The code is down below, thanks in advance.

echo Print out all content ^<1^> 
echo Add a new number ^<2^> 
echo Delete a number ^<3^> 
echo Search ^<4^> 
echo Exit ^<5^> 
set /p val="Choose between 1-5: " 

GOTO CASE_%val% 
:CASE_1 for /f "tokens=*" %%a in 
(telephoneregister.txt) do 
( echo %%a ) 
GOTO END_SWITCH 
:CASE_2 echo "Number: " set /p p1="Nr" 
echo %p1% >> %output%\telephoneregister.txt 
GOTO END_SWITCH 
:CASE_3 echo "Which number would you like to delete? " 
set /p num="Telephoneregister" 
type telephoneregister.txt | findstr /v %num% >telephoneregister.txt del /s telephoneregister.txt 
type telephoneregister.txt > tele.txt del /s tele1.txt 
GOTO END_SWITCH 
:CASE_4 set /p n1="Number: "
 findstr %n1% telephoneregister.txt 
GOTO END_SWITCH 
:CASE_5 exit 0
 GOTO END_SWITCH 
:END_SWITCH 
pause

I got to this code here:

@echo off
:menu
cls
echo 1- Print out all content 
echo 2- Add a new number
echo 3- Delete a number
echo 4- Search
echo 5- Exit 
set /p val="Choose between 1-5: " 
if %val%== 1 goto one
if %val%== 2 goto two
if %val%==3 goto three
if %val%== 4 goto four
if %val%== 5 goto five

:one
cls
type telephoneregister.txt
echo.
echo ====================
set /p =ENTER to go back to menu.
goto menu

:two
cls
set /p p1="Number: " 
echo %p1% >> telephoneregister.txt
echo. 
echo ====================
set /p =ENTER to go back to menu.
goto menu

:three
cls
echo Which number would you like to delete?
set /p num="Telephoneregister: " 
type telephoneregister.txt | findstr /v %num% >telephoneregister.txt del /s telephoneregister.txt 
type telephoneregister.txt > tele.txt del /s tele1.txt 
set /p =ENTER to go back to menu.
goto menu

:four
cls
set /p n1="Number: "
findstr /r /c:%n1% telephoneregister.txt
echo.
echo ====================
SET /p =ENTER to go back to menu.
goto menu

:five
exit

It's not completely done yet (Option 3 It's not working) but you can see what you had wrong, and probably come to the solution searching on the web. If you have any question in the code above, Just ask! Good luck.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM