You are not logged in.

#1 23 Nov 2015 03:05

joskuzera
Member
Registered: 05 Oct 2015
Posts: 5

Adding multiply user entered letters that will then provide more outpu

I got a hand writing this code from someone on here awhile back which turned out to work just as i wanted, now a new problem has came to my attention this program will tell the user how many environment variables start with the letter they input, now what is i want them to be able to put in more then one letter separated by a space and it will tell them how many start with all, lets say 5 letters total?


SETLOCAL
SET /p "letter=Choose a letter "

if "%letter%" == "" (
   echo Usage: Please enter a letter!
   pause
   exit /b 1
)
SET "letter=%letter:~0,1%"
FOR /f %%a IN ('2^>nul set %letter% ^|find /c "=" ' ) DO SET count=%%a
shift /1
ECHO %count% variables START "%letter%"
pause

Offline

#2 23 Nov 2015 09:46

foxidrive
Member
Registered: 04 Apr 2013
Posts: 339

Re: Adding multiply user entered letters that will then provide more outpu

I modified your code - test it to see how it goes.

@echo off
SETLOCAL
:begin
SET /p "letter=Choose a letter "

if "%letter%" == "" (
   echo Usage: Please enter a letter!
   pause
   cls
   goto :begin
)
          for %%a in (%letter%) do call :routine %%a
          pause
          goto :eof

:routine
          set letter2=%1
          FOR /f %%a IN ('2^>nul set "%letter2:~0,1%" ^|find /c "=" ' ) do  ECHO %%a variables START with "%letter2:~0,1%"

Offline

#3 23 Nov 2015 15:00

joskuzera
Member
Registered: 05 Oct 2015
Posts: 5

Re: Adding multiply user entered letters that will then provide more outpu

foxidrive wrote:

I modified your code - test it to see how it goes.

@echo off
SETLOCAL
:begin
SET /p "letter=Choose a letter "

if "%letter%" == "" (
   echo Usage: Please enter a letter!
   pause
   cls
   goto :begin
)
          for %%a in (%letter%) do call :routine %%a
          pause
          goto :eof

:routine
          set letter2=%1
          FOR /f %%a IN ('2^>nul set "%letter2:~0,1%" ^|find /c "=" ' ) do  ECHO %%a variables START with "%letter2:~0,1%"

Thanks, if you have the time would you be able to explain how your for loop that you added works?

Offline

#4 23 Nov 2015 22:38

foxidrive
Member
Registered: 04 Apr 2013
Posts: 339

Re: Adding multiply user entered letters that will then provide more outpu

Put an echo keyword before the call keyword and run it.
It should give you a clue as to how it works.

Offline

Board footer

Powered by