Solved Interactive batch with dynamic variables

October 25, 2011 at 00:06:31
Specs: Windows XP
I would like to get the value(their sum) of the letter or letters I entered

set /p ABCDEFJHIJKLMNO etc=enter letter(S)
set /a A=15
set /a B=50
set /a C=70
set /a D=90
etc
echo !A!!C!!D!>>new.txt

so I want the sum of what I entered
for example if I entered ACD I want to get=175

Any help will be scored very high

thanks


See More: Interactive batch with dynamic variables

Report •

✔ Best Answer
October 28, 2011 at 02:11:47
Hope this does what you want:

@echo off
cls
setlocal enabledelayedexpansion

set A=15&set B=50&set C=70&set D=90&set E=110&set F=130&set G=150
set H=170&                        :: etc... etc...
set /p string="   Enter string to be converted... "
cls

:loop
call set chr=%%string:~!nbr!,1%%
if not defined chr goto endit
set /a total=%total%+%chr%
set chr=
set /a nbr+=1
goto loop

:endit
echo %total%>>%temp%\new.txt

type %temp%\new.txt


Please come back & tell us if your problem is resolved.



#1
October 25, 2011 at 11:51:22
@echo off

::begin data entry

:: request data

set /A F=0
set /A G=0
set /A H=0
set /A I=0
SET /A SUMMA=0

:begining
CLS
ECHO.
echo BEGIN DATA ENTRY HERE(PRESS Z TO EXIT)
echo.

SET /P GR=PLEASE ENTER GRADE
SET A=A
SET B=B
SET C=C
SET D=D
SET Z=Z

IF %GR% EQU %A% GOTO LA1
IF %GR% EQU %B% GOTO LA2
IF %GR% EQU %C% GOTO LA3
IF %GR% EQU %D% GOTO LA4
IF %GR% EQU %Z% GOTO LA5

GOTO begining
GOTO SKIP1
:LA1
SET /A SUMMA=%SUMMA%+15
set /A F=%F%+1
ECHO %SUMMA%
GOTO begining
PAUSE
:SKIP1

GOTO SKIP2
:LA2
SET /A SUMMA=%SUMMA%+50
set /A G=%G%+1
ECHO %SUMMA%
GOTO begining
PAUSE
:SKIP2

GOTO SKIP3
:LA3
SET /A SUMMA=%SUMMA%+70
set /A H=%H%+1
ECHO %SUMMA%
GOTO begining
PAUSE
:SKIP3

GOTO SKIP4
:LA4
SET /A SUMMA=%SUMMA%+90
set /A I=%I%+1
ECHO %SUMMA%

GOTO begining
PAUSE
:SKIP4

GOTO SKIP5
:LA5
GOTO ending
PAUSE
:SKIP5


ECHO %SUMMA%
PAUSE
GOTO begining

PAUSE

:ending


echo TOTAL IS %SUMMA%
ECHO A's are %F%
ECHO A's are %G%
ECHO A's are %H%
ECHO A's are %I%

pause

:eof

mike


Report •

#2
October 25, 2011 at 23:29:12
Hi Mike thank you for your kindness u are grace

I want you to have a clear idea about my request I am doing statistics all the english alphabets are needed and each letter has its fixed value I need to get several letters in various combination (eg ADMN or ABCF KLMNHFOP and so on)from their value (sum) I will get a bar(histogram)

in the batch (you kindly wrote for me) any letter(s) I enter is licked out immediately

thanks again >>>>>>>I hope u will not give up


Report •

#3
October 26, 2011 at 05:21:45
this set up would only read (1) one letter at a time. are you attempting to enter a string? (i understand that you need the whole alphabet).

mike


Report •

Related Solutions

#4
October 28, 2011 at 00:18:11
Hi mike thanks
even single letter is rejected

Report •

#5
October 28, 2011 at 02:11:47
✔ Best Answer
Hope this does what you want:

@echo off
cls
setlocal enabledelayedexpansion

set A=15&set B=50&set C=70&set D=90&set E=110&set F=130&set G=150
set H=170&                        :: etc... etc...
set /p string="   Enter string to be converted... "
cls

:loop
call set chr=%%string:~!nbr!,1%%
if not defined chr goto endit
set /a total=%total%+%chr%
set chr=
set /a nbr+=1
goto loop

:endit
echo %total%>>%temp%\new.txt

type %temp%\new.txt


Please come back & tell us if your problem is resolved.


Report •

#6
October 29, 2011 at 00:30:48
Hi Wahine You did it perfectly
my hard work has been reduced to nul by your help
any word in english literature to express my feelings you deserve

more than that
I am praying for u to keep you away from what you are afraid of
(I guess Ca)
thanks you very very much
by the way it is time now to ask for a batch to get me to my
workplace instead of using my car!!!


Report •

Ask Question