0

Simply put, it's

set /a mm=%r:~2,3%

BUT, the 2 is codified as set /a d=2 and the 3 is codified as set /a l=3.

So, now how do I write the first expression using the codified variables?

i.e. set /a mm=%r:~%d%,%l%% doesn't work. What's the gimmick?

I've tried...

set /a mm="%r:~(%%d),%%l%" and all kinds of other codifications but the % usage throws me.

aschipfl
  • 33,626
  • 12
  • 54
  • 99
  • Does this answer your question? [windows batch command nested variable](https://stackoverflow.com/questions/46067287/windows-batch-command-nested-variable) Specifically, add `setlocal enabledelayedexpansion` to the top of your script and use `!r:~%d%,%l%!` – SomethingDark Dec 03 '22 at 04:07
  • 1
    `CALL SET "mm=%%r:~%d%,%l%%%"` The quotes may be omitted, but be careful. If the first character of the substring calculated is `0`, then batch defines it as OCTAL, so you are likely to get unexpected results - in fact, if any of the remaining characters are `8` or `9` then you'll get an error since `8` and `9` are invalid octal characters. – Magoo Dec 03 '22 at 05:37
  • SomethingDark, It might if I can figure out what they are trying to say, I'll study that and learn. Lol. Thanks Magoo, the CALL set rather than set seems to have been it. ::: 1000 so 3 digits accuracy right of decimal point. set /a lngt=3 set /a digi=(%len%-%lngt%) echo * & echo . & echo len==%len% digi==%digi% REM set /a mm=%r:~2,3% call set /a mm=(%%r:~%digi%,3%%%) Does it. It's a part of something that bypasses using modulus and going fractional and just adds 3 digits by multiplying the numerator by 1000, then sliding the decimal point to the left 3 in the result. Works Great! – Global.access.software Dec 03 '22 at 06:27
  • @SomethingDark, No, the specifically part doesn't work like that, it gets returned from this function via set "%~2=%mm%" and the returned value comes back as "" for both values returned. With of without a CALL set – Global.access.software Dec 03 '22 at 06:42
  • If you're calling the subroutine from inside a set of parentheses, then you'd need to reference `!d!` and `!l!` instead, but code doesn't appear in comments correctly so it's hard to see what you're using. – SomethingDark Dec 03 '22 at 06:58

1 Answers1

0
@echo off
::: Experimental Module
set /a s=0
title %date% @ %time% playtime.bat by -JpE-

:start
if %s% geq 2 cls & set /a s=0
echo .
echo .
echo %date% @ %time%
set /a a=11 & set /a b=4 & set /a c=115
echo .
set /a s+=1
echo a==%a%, b==%b%, c==%c%
call :funct1 a,b,c
goto start

::::::::::::::::::::::::::::::::::::::::::::


:funct1
set g=%~2
set h=%~3
call :funct2 z,x,%g%,%h%
call :funct4 %z%,%x%,%g%,%h%
exit /b %errorlevel%


:funct2 <ReturnVar1, ReturnVar2, Arg_g, Arg_h>
set /a g=%~3 & set /a h=%~4
set /a r=1
set /a d=1000

if %g% neq 0 if %g% gtr 0 set /a r=(%d%*%~4/%~3)

::: Return z & x as %~1 & %~2
call :funct3 z,x,r
::::::::::::::::::::::::::::

set "%~1=%z%"
set "%~2=%x%"
exit /b %errorlevel%


::: Calc :::
:funct3 <rr,mm,r>
set /a r=%~3

set bats=C:\Users\JpE\Documents\AAA Sync2Laptop\Batch Files\BCS-Suite
set strlen="%bats%\string_length.bat"
call %strlen% len,r 
REM echo length of %r% is %len%
::: 1000 so 3 digits accuracy right of decimal point.
set /a lngt=3
set /a digi=(%len%-%lngt%)
echo * & echo . & echo len==%len% digi==%digi%
:::::::::::::::::::::::::
REM set /a mm=%r:~2,3%
call set /a mm=(%%r:~%digi%,%lngt%%%)
:::::::::::::::::::::::::
set /a rr=(%r%/1000)

::: Okay to here :::
echo sending back from funct3: rr==%rr%, mm==%mm%
set "%~1=%rr%"
set "%~2=%mm%"
exit /b %errorlevel%



::: Display :::
:funct4 <rr,mm,a,b,c>
echo .
echo A == %a%
echo B == %b%
echo C == %c%

echo .
echo C / B == %rr%.%mm%
echo .
pause
echo .
echo .
exit /b %errorlevel%


:return

echo Program Terminating
pause
  • 3
    STOP IT! Do not use `Set` with its `/A` option if you are not performing arithmetic, or using any of its functionality. The `/A` option does not signify that the variable is numeric, all variables are strings. It looks like you only need it in three places: here ```set /a r=(%d%*%~4/%~3)```, _which should be ```set /a "r=(d * %~4) / %~3"```, or ```set /a r=d * %~4 / %~3``` anyhow_; here ```set /a digi=(%len%-%lngt%)```, _which should be ```set /a digi=len - lngt```_, and here ```set /a rr=(%r%/1000)```, _which should be ```set /a rr=r / 1000```_. All other instances of `/a` can be removed. – Compo Dec 03 '22 at 10:28
  • @Compo Ah, okay. So it is simpler than I tried to make it, lol. I'm missing a fundamental about using the delimiters " and % somewhere messing with several languages. Thank You! – Global.access.software Dec 04 '22 at 03:12