help correcting this code
Moderator: DosItHelp
help correcting this code
wassup people... i believe i got the functions here wrong... any tips to get it to do what its suppose to do
@echo off
:begin
cls
echo ^>^>^>^> Test Nisse's phone records ^<^<^<^<
echo.
echo ^<1^> search for phone numbers
echo ^<2^> enter a new phone number
echo ^<3^> remove phone number
echo ^<4^> Print records on screen
echo.
echo ^<x^> Exit
set /p val=What's your choice (1-4)
if %val% == 1 goto :type C:\records.txt
if %val% == 2 goto :edit C:\records.txt
if %val% == 3 goto :edit C:\records.txt
if %val% == 4 goto :type C:\records.txt
if %val% == x goto :exit
goto :begin
:type C:\records.txt
type C:\records.txt
pause
goto :begin
:edit C:\records.txt
edit C:\records.txt
pause
goto :begin
:edit C:\records.txt
edit C:\records.txt
goto :begin
:ps C:\records.txt
type C:\records.txt
pause
goto :begin
:exit
exit
goto :quit
:quit
@echo off
:begin
cls
echo ^>^>^>^> Test Nisse's phone records ^<^<^<^<
echo.
echo ^<1^> search for phone numbers
echo ^<2^> enter a new phone number
echo ^<3^> remove phone number
echo ^<4^> Print records on screen
echo.
echo ^<x^> Exit
set /p val=What's your choice (1-4)
if %val% == 1 goto :type C:\records.txt
if %val% == 2 goto :edit C:\records.txt
if %val% == 3 goto :edit C:\records.txt
if %val% == 4 goto :type C:\records.txt
if %val% == x goto :exit
goto :begin
:type C:\records.txt
type C:\records.txt
pause
goto :begin
:edit C:\records.txt
edit C:\records.txt
pause
goto :begin
:edit C:\records.txt
edit C:\records.txt
goto :begin
:ps C:\records.txt
type C:\records.txt
pause
goto :begin
:exit
exit
goto :quit
:quit
Re: help correcting this code
depends on the task, for example:
Code: Select all
@echo off
:begin
cls
echo ^>^>^>^> Test Nisse's phone records ^<^<^<^<
echo.
echo ^<1^> Search for phone numbers
echo ^<2^> Enter a new phone number
echo ^<3^> Remove phone number
echo ^<4^> Print records on screen
echo.
echo ^<x^> Exit
set /p "val=What's your choice (1-4): "
if "%val%"=="1" call :sub1 "C:\records.txt"& goto :begin
if "%val%"=="2" call :sub2 "C:\records.txt"& goto :begin
if "%val%"=="3" call :sub3 "C:\records.txt"& goto :begin
if "%val%"=="4" call :sub4 "C:\records.txt"& goto :begin
if /i not "%val%"=="x" call goto begin
goto :quit
:sub1
type "%~1"
pause
goto :eof
:sub2
edit "%~1"
pause
goto :eof
:sub3
edit "%~1"
pause
goto :eof
:sub4
type "%~1"
pause
goto :eof
:quit
exit
Re: help correcting this code
!!! i dont see how this is different from what i posted. ur doing the same thing i am which is wrong. what i need is for it to do what it says when 1-4 are entered
Re: help correcting this code
Try this
Regards
aGerman
Code: Select all
@echo off
:begin
cls
echo ^>^>^>^> Test Nisse's phone records ^<^<^<^<
echo.
echo ^<1^> Search for phone numbers
echo ^<2^> Enter a new phone number
echo ^<3^> Remove phone number
echo ^<4^> Print records on screen
echo.
echo ^<x^> Exit
set /p "val=What's your choice (1-4): "
if "%val%"=="1" call :sub1 "C:\records.txt"& goto :begin
if "%val%"=="2" call :sub2 "C:\records.txt"& goto :begin
if "%val%"=="3" call :sub3 "C:\records.txt"& goto :begin
if "%val%"=="4" call :sub4 "C:\records.txt"& goto :begin
if /i not "%val%"=="x" call goto begin
goto :eof
:sub1
set "name="
set /p "name=Enter a name: "
if not defined name goto :eof
for /f "delims=: tokens=1*" %%i in ('findstr /i /c:"%name%" "%~1"') do echo Name: %%i Number: %%j
pause
goto :eof
:sub2
set "name="
set /p "name=Enter the name: "
if not defined name goto :eof
set "number="
set /p "number=Enter the number: "
if not defined number goto :eof
>>"%~1" echo %name%:%number%
goto :eof
:sub3
set "name="
set /p "name=Enter the name: "
if not defined name goto :eof
move "%~1" "%temp%\tmp.txt"
for /f "delims=" %%a in ('findstr /i /v /c:"%name%" "%temp%\tmp.txt"') do >>"%~1" echo %%a
del "%temp%\tmp.txt"
goto :eof
:sub4
for /f "usebackq delims=: tokens=1*" %%i in ("%~1") do echo Name: %%i Number: %%j
pause
goto :eof
Regards
aGerman
can someone correct it
well this code is correct for some of the functions but it doesnt actually save/overwrite to the original file?!!!
can someone correct that
can someone correct that
Re: help correcting this code
Which "original file" is meant? Names and numbers are searched/saved/removed/displayed from "C:\records.txt". What else should happen?
Sorry, but I've no idea what you mean. You should give some more verbose informations to us.
Regards
aGerman
Sorry, but I've no idea what you mean. You should give some more verbose informations to us.
Regards
aGerman
Re: help correcting this code
well im glad its you... its suppose to do exactly what you just said to the file records.txt... but when i actually ran it, it doesnt actuallt alter the file. after i run it and do some changes i open the original file and it still has the same info without any of the alterations!!! what am i doing wrong
Re: help correcting this code
Strange. It workes absolutely fine for me. So I don't know why it shouldn't work for you as well. Did you try exactly the same code?
Re: help correcting this code
yes!am i not suppose to!