The problem lies in this part of the code:
for /l %%x in (1, 1, %num%) do (
set /p "inp=Enter Ext of PC: "
echo pc-%inp%x>>"Myfile.log"
)
Here is the full code:
@ECHO OFF
:: +++++++++++++++++++ MENU +++++++++++++++++++++
:menu
cls
echo.
echo 1) Add PCs to Log File
echo 2) View Log File
echo 3) Exit
echo.
goto option
:option
set /p op=Type option #:
if "%op%"=="1" goto addext
if "%op%"=="2" goto viewcnt
if "%op%"=="3" goto exit
:: ++++++++++++++++++++ OPTIONS ++++++++++++++++++++++
:addext
:: Enter Number of PCs to Add to Log File
echo.
set /p "num=Enter Num of PCs to Add: "
echo.
goto addlog
:addlog
:: Create/Clear Log File/Enter Computer Extensions/Write to Log File
cls
echo.
echo.>"Myfile.log"
for /l %%x in (1, 1, %num%) do (
set /p "inp=Enter Ext of PC: "
echo pc-%inp%x>>"Myfile.log"
)
echo.
pause
goto menu
:viewcnt
:: View Log File
type Myfile.log
echo.
pause
goto menu
:exit
@exit
Objectives
Enter Number of PCs to Add to Log File - Works
set /p "num=Enter Num of PCs to Add To: "
Output:
Enter Num of PCs to Add To:
Create / Erase Log File (each time option 1 of menu is choosen) - Works
echo.>"Myfile.log"
Set variable %inp%
for each of the Number of Computers from %num%
variable - Need Help
for /l %%x in (1, 1, %num%) do (
set /p "inp=Enter Ext of PC: "
echo pc-%inp%x>>"Myfile.log"
)
Output:
Enter Ext of PC:
(Iterates the number of times %num%
is equal to)
- Prompts for input of extension variable for the number of times prescribed by previous input - Works
- Able to type in each extension - Works
- Not sure what happens to the variable entered - Need Help
Write the Variables to the Log File - Need Help
echo pc-%inp%x>>"Myfile.log"
- The prefix preceding the variable shows the number of times entered - Works
- Not including the inputted variables - Need Help
View Log File - Works
type Myfile.log
Further Considerations:
pc-%inp%
is the computer name ( prefix: pc- ) followed by (variable:%inp%
/ example: pc-a001 )%inp%
needs to be Alphanumberic ( one letter followed by 3 numbers: a001 )
-%inp%x
with-!inp!x
as well.