How to? need help with "function"

Aug 2, 2011
258
4
Berlin, Germany
Hi all,

I want to format a csv report to a human-readable style.
The report contains fields for nas-volumes, eg. volume size.
The size field is notated in KB and I want to replace it with MB, GB, TB if reasonable.

So in the first step I want to create a function which should return a numeric value divided by 1024 if reasonalble. But it doesn't work as expected. Have a look at this:

Code:
C:\Temp >function tomega=%%@if[ %%@eval[ %%1 mod 1024 ] eq 0,%%@eval[%%1/1024] (true),%%1 (false)]
 
C:\Temp >function
tomega=%@if[ %@eval[ %1 mod 1024 ] eq 0,%@eval[%1/1024] (true),%1 (false)]
 
C:\Temp >set val=16384
 
C:\Temp >echo %@tomega[%val]
16 (true)
 
C:\Temp >set val=123456
 
C:\Temp >echo %@tomega[%val]
5625 (true),123456 (false)                             <- unexpected
 
rem    with back quotes    *************************
 
C:\Temp >function tomega=`%@if[ %@eval[ %1 mod 1024 ] eq 0,%@eval[%1/1024] (true),%1 (false)]`
 
C:\Temp >function
tomega=%@if[ %@eval[ %1 mod 1024 ] eq 0,%@eval[%1/1024] (true),%1 (false)]
 
C:\Temp >set val=16384
 
C:\Temp >echo %@tomega[%val]
16 (true)
 
C:\Temp >set val=123456
 
C:\Temp >echo %@tomega[%val]
5625 (true),123456 (false)                             <- unexpected

Why are both values true/false evaluated and given back?

regards
Frank
 
May 20, 2008
11,400
99
Syracuse, NY, USA
Why are both values true/false evaluated and given back?
I don't see that:

Code:
v:\> function tomega=`%@if[ %@eval[ %1 mod 1024 ] eq 0,%@eval[%1/1024] (true),%1 (false)]`
 
v:\> function
tomega=%@if[ %@eval[ %1 mod 1024 ] eq 0,%@eval[%1/1024] (true),%1 (false)]
 
v:\> set val=16384
 
v:\> echo %@tomega[%val]
16 (true)
 
v:\> set val=123456
 
v:\> echo %@tomega[%val]
123456 (false)

And I can't figure out where 5625 may have come from.
 

rconn

Administrator
Staff member
May 14, 2008
12,344
149
Not reproducible here:

[D:\jpsoft.com]function tomega=%%@if[ %%@eval[ %%1 mod 1024 ] eq 0,%%@eval[%%1/1024] (true),%%1 (false)]

[D:\jpsoft.com]function
tomega=%@if[ %@eval[ %1 mod 1024 ] eq 0,%@eval[%1/1024] (true),%1 (false)]

[D:\jpsoft.com]set val=16384

[D:\jpsoft.com]echo %@tomega[%val]
16 (true)

[D:\jpsoft.com]set val=123456

[D:\jpsoft.com\images]echo %@tomega[%val]
123456 (false)

Are you sure you don't have an alias or another UDF getting in the way?
 
Aug 2, 2011
258
4
Berlin, Germany
Hi,

I still have the problem, but I suppose it is a language-/country-problem.
Perhaps there is 1 comma to much bugging the function:

Code:
C:\Temp >ver /r
 
TCC  13.01.30 x64  Windows 2008R2 [Version 6.1.7601]
TCC Build 30  Windows 2008R2 Build 7601  Service Pack 1
Registered to ********************
 
C:\Temp >unalias *
 
C:\Temp >alias
TCC: No aliases defined
 
C:\Temp >function tomega=`%@if[ %@eval[ %1 mod 1024 ] eq 0,%@eval[%1/1024] (true),%1 (false)]`
 
C:\Temp >function
tomega=%@if[ %@eval[ %1 mod 1024 ] eq 0,%@eval[%1/1024] (true),%1 (false)]
 
C:\Temp >set val=16384
 
C:\Temp >echo %@eval[%val/1024]
16
 
C:\Temp >echo %@tomega[%val]
16 (true)
 
C:\Temp >set val=123456
 
C:\Temp >echo %@eval[%val/1024]
120,5625
 
C:\Temp >echo %@tomega[%val]
5625 (true),123456 (false)
 
Aug 2, 2011
258
4
Berlin, Germany
ok, I can follow that "function" is fragile concerning commas.
But I don't know the addons you mentioned. Isn't there a more common and easy way to accomplish it?

btw:
I wish you all a happy new year!
 
May 20, 2008
11,400
99
Syracuse, NY, USA
ok, I can follow that "function" is fragile concerning commas.
But I don't know the addons you mentioned. Isn't there a more common and easy way to accomplish it?

The stray comma and the 5625 are probably coming from @EVAL[ 123456 / 1024 ] (120.5625). You can use @EVAL[ %1 \ 1024 ]. That's the integer quotient and won't create a decimal separator.
 
Aug 2, 2011
258
4
Berlin, Germany
:oops: thank you for explaining me that DWIM was meant sarcastic :D Unfortunately I'm not so familiar with the american or english language.

OK, I will find an workaround to avoid the stray comma.

Thank you.

regards
Frank
 
Aug 2, 2011
258
4
Berlin, Germany
Code:
C:\Temp >function tomega=`%@if[ %@eval[ %1 mod 1024 ] eq 0,%@eval[%1 \ 1024] (true),%1 (false)]`
 
C:\Temp >function
tomega=%@if[ %@eval[ %1 mod 1024 ] eq 0,%@eval[%1 \ 1024] (true),%1 (false)]
 
C:\Temp >set val=16384
 
C:\Temp >echo %@tomega[%val]
16 (true)
 
C:\Temp >set val=123456
 
C:\Temp >echo %@tomega[%val]
123456 (false)

So everything is fine now.

regards
Frank
 
Similar threads
Thread starter Title Forum Replies Date
vefatica Need help with XML Support 3
MikeBaas How to? I need help with RD Support 5
J Need activation help. Support 1
C Cmpr_Del.btm need help understanding UDF..... Support 2
R How to? i need a little help Support 3
S Need help to execute TCC commands on another system Support 6
H I need a little help. Support 4
M Need help Support 0
D Need to set Take Command font size when switching to high DPI display Support 0
vefatica gcd() and lcm() ... need '%' Support 10
C Touch command — I Need to touch matching files in another directory. Support 5
D I need a debug-plan Support 4
vefatica New desktop, need Explorer PID Support 1
B Need To Deactivate V12.1 Before Reinstall To Different Directory? Support 3
S Re: Release of new version - do we need to download again? Support 8
O Need 'grep' equivalent Support 13
vefatica What environment variables does IDE need? Support 3
T Expired trial...need to evaluate new build Support 1
C how to copy to folder where I need admin rights Support 5
deleyd Need example of @COMPARE Support 1
P Need to use a regex in a "for" loop. Support 54
H New to TCC and I need assistance Support 8
C Add link to ewriter help to program group... Support 3
samintz How to? Search for %(command) in Help? Support 1
Joe Caverly Favorites in eWriter Help Support 6
Joe Caverly Quick Search in eWriter Help Support 1
vefatica Online help? Support 2
fishman@panix.com HELP!! I just updated to Version 28 and as usual I cannot make extended directory search work. Support 2
JohnQSmith New online help file wrong logo Support 7
Jay Sage Documentation Function @DRIVE Missing in Help Lists Support 0
Charles Dye More help nits Support 0
D Documentation Typo in COPY help Support 0
FreezerBurnt Help making a CMD and TCC compatible batch file Support 7
Joe Caverly Documentation COMMANDS in Version 27 help Support 8
K_Meinhard How to? Help window position Support 7
U Command help on file names Support 5
D Documentation Help "Startup" page does not describe global lists Support 0
vefatica Help disappears? Support 6
rchapmanitt Help Purchasing Support 2
Charles Dye Documentation Help nits: @ZIPFILECRC Support 0
C version help Support 3
C Documentation Help Nit. REN / RENAME Support 0
Dmitry L. Kobyakov Documentation Error in the Help: the WINDOW command Support 0
vefatica Help for @PID Support 2
Alpengreis Documentation Minor issue in help file for view /E Support 1
R Documentation Advanced Directives Help Support 0
R Documentation Help Nit with SETP Support 0
R wmic command help Support 9
R Documentation Help Nit > bdebugger View Menu Support 0
R Documentation A couple of Help nits Support 0

Similar threads