Page 1 of 1
help correcting this code
Posted: 16 Jun 2010 21:22
by mohamad
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
Re: help correcting this code
Posted: 16 Jun 2010 22:56
by amel27
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
Posted: 17 Jun 2010 15:21
by mohamad
!!! 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
Posted: 17 Jun 2010 16:24
by aGerman
Try this
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
Posted: 25 Jun 2010 12:50
by mohamad
well this code is correct for some of the functions but it doesnt actually save/overwrite to the original file?!!!
can someone correct that
Re: help correcting this code
Posted: 25 Jun 2010 13:16
by aGerman
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
Re: help correcting this code
Posted: 25 Jun 2010 13:37
by mohamad
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
Posted: 25 Jun 2010 13:59
by aGerman
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
Posted: 26 Jun 2010 03:38
by mohamad
yes!am i not suppose to!