Note also 2nd called batch (Value verifier used twice)= M-CkV
Methinks great interface.
Well commented for those who are interested.
Batch has some extra logic to handle optional
user choice decimal positions for division (only).
Includes user entry and command line parameter options.
For USER ENTRY METHOD subsequent runs,
allows optional retention of current function
and user entered division decimal positions.
Also can optionally set 1st value to current result.
Note: Included beeps at key points. Echo:
No idea if these work. Delete if you wish.
No doubt some real pros out there can tweak improve my structure.
Please, feel free. Many! hours to make. Best I could do.
Code: Select all
@Echo Off
REM DECIMAL MATH CALCULATOR BATCH
REM USING RUN TIME ENTERED VALUES OR
REM COMMAND PARAMETER ENTERED VALUES
REM COMMAND LINE THEN BECOMES- Math F V1 V2 #
REM [F lower case made upper, defaults to A if not ASMD or smd]
REM F=Function (ASMD), V1=1st Value, V2=2nd Value, (D only) #=Decimal positions wanted
REM For D, decimal values are rounded to # positions if given
Set G=
Set R#=0
Set /P=Set R=>M-SetR.txt<nul
:REDO
Color 0C
ClS
Echo:DECIMAL MATH CALCULATOR BATCH
If !%1==! GoTo Start
Echo:COMMAND PARAMETER ENTERED VALUES
Echo.
Set F=%1
Set V1=%2
Set V2=%3
Set #=%4
Set H#=%#%
GoTo CkF
:Start
Echo: USER ENTERED VALUES
Echo.
If !%G%==!F Echo:Retained Function= %HF%
If !%G%==!B Echo:Retained Function= %HF%
If !%G%==!F GoTo GetV
If !%G%==!B GoTo GetV2
:GETF
Echo:
Echo:Enter 1st letter of function
Choice /C ASMD
If Errorlevel==1 Set F=A
If Errorlevel==2 Set F=S
If Errorlevel==3 Set F=M
If Errorlevel==4 Set F=D
:CKF
REM ***** Set Funtion
Set HF=%F%
If !%F%==!s Set HF=S
If !%HF%==!S GoTo GotF
If !%F%==!m Set HF=M
If !%HF%==!M GoTo GotF
If !%F%==!d Set HF=D
If !%HF%==!D GoTo GotF
If Not !%HF%==!A Set HF=A
:GOTF
If %HF%==A Set F=+
If %HF%==S Set F=-
If %HF%==M Set F=*
If %HF%==D Set F=/
If !%G%==!V GoTo GetV2
:GETV
If !%1==! Echo:
If !%1==! Set /P V1= Enter 1st Value:
REM ***** Verify valid V1
Set Ck=%V1%
Call M-CkV
If Not %Ck%==X GoTo GetV2
If Not !%1==! GoTo Done
GoTo GetV
:GETV2
Color 0E
If !%G%==!B GoTo RT1
If !%G%==!V GoTo RT1
If %F%%G%==/K GoTo RTF
GoTo NoRtn
:RT1
Echo:Retained 1st Value= %V1%
If Not %F%%G%==/B GoTo Pause
:RTF
Echo:Retained Fraction Positions= %#%
:PAUSE
Pause
:NORTN
Color 0C
If !%1==! Echo:
:REGETV2
If !%1==! Set /P V2= Enter 2nd Value:
REM ***** Verify valid V2
Set Ck=%V2%
Call M-CkV
If Not %Ck%==X GoTo Do#
If Not !%1==! GoTo Done
GoTo ReGetV2
:DO#
If Not %F%==/ GoTo Go
If !%G%==!K GoTo Go
If !%G%==!B GoTo Go
If !%1==! Echo:
If !%1==! Set /P #= Enter # of Fraction Positions if desired:
REM ***** Verify valid #
If !%#%==!0 Set #=
If !%#%==! GoTo Go
Set /A Ck=#*1
If %#%==%Ck% GoTo Go
Echo.
Echo:
Color 0F
Echo:# = %#% NOT NUMERIC
Echo.
If Not !%1==! GoTo Done
Pause
Color 0C
GoTo Do#
:GO
Set H#=%#%
Set G=
If Not !%1==! GoTo Calc
REM ***** Allow user to examine entries
ClS
Echo:
Color 02
ClS
Echo:Function= %HF%
Echo:1st Value= %V1%
Echo:2nd Value= %V2%
If %F%==/ Echo:Positions= %#%
Set /P G= Press Enter if all OK, Other to redo
If Not !%G%==! GoTo Redo
Color 0C
ClS
Echo:DECIMAL MATH CALCULATOR BATCH
Echo: USER ENTERED VALUES
Echo.
:CALC
REM ***** Do Calculation
Powershell %V1%%F%%V2%>Result.txt
Copy M-SetR.txt+Result.txt Result.bat>nul
Call Result.bat
If Not %F%==/ GoTo Show
If !%#%==! GoTo Show
Set /a RW=R*1
If Not !%D%==! GoTo DoD
Set D=1
Setlocal EnableDelayedExpansion
For /L %%I in (1,1,!#!) Do Set "D=!D!0"
Endlocal &Set "D=%D%"
:DOD
REM ***** Get Whole
Powershell ((%R%-%RW%)*%D%0)+5>Result.txt
Copy M-SetR.txt+Result.txt Result.bat>nul
Call Result.bat
Set /A R=(R+1)/10
REM ***** Get Fraction & build Result
Powershell %RW%+(%R%/%D%)>Result.txt
Copy M-SetR.txt+Result.txt Result.bat>nul
Call Result.bat
:SHOW
Echo:
Echo:RESULT= %R%
Set /A R#=%R#%+1
Set R%R#%=%R%
Set Ck=
Set RW=
Echo.
If Not !%1==! GoTo Clear
Echo:
Echo:Enter G, F, V or B to do Another Calculation or Enter if Done
Echo:F - Function and Decimal Positions retained
Echo:V - V1 set to Current Result
Echo:B - Both as F and V
Set /P G=
If !%G%==! GoTo Done
Set #=%H#%
If !%G%==!f Set G=F
If !%G%==!F GoTo Redo
Set V1=%R%
If !%G%==!b Set G=B
If !%G%==!B GoTo Redo
Set D=
If !%G%==!g Set G=G
If !%G%==!G GoTo Redo
If !%G%==!v Set G=V
If !%G%==!V GoTo Redo
:DONE
If %R#%==1 GoTo Clear
Color 0D
ClS
Echo:ALL RESULTS
Echo.
Setlocal EnableDelayedExpansion
For /F "tokens=1*delims==" %%A in ('Set R') Do Echo:%%A= %%B
Endlocal
Pause
:CLEAR
Color
Del M-SetR.txt>nul
Del Result.*>nul
Set G=
Set F=
Set #=
Set V1=
Set V2=
Set HF=
Set H#=
Set D=
Set R=
Set R#=
M-CkV.bat
@ECHO Off
REM ***** Verify valid Value for math calculation
If !%Ck%==! Set Ck=Null
If %Ck%==Null GoTo Inv
Set /a RW=Ck+0
Powershell (%Ck%-%RW%)+%RW%>Result.txt
If %errorlevel%==1 GoTo Inv
Copy M-SetR.txt+Result.txt Result.bat >nul
Call Result.bat
If %Ck%==%R% GoTo X
If Not %RW%==0 GoTo Inv
If 0%Ck%==%R% GoTo X
:Inv
Echo.
Echo:
Color 0E
Echo:V = %Ck% - INVALID
Echo.
Pause
Set Ck=X
Color 0C
:X