Batch file comparison problem.

October 12, 2012 at 01:43:10
Specs: Windows 7 Pro, Intel(R) Core(TM) i3 / 3.20 GHz / 8 GB Ram
Hi.

I need to compare numbers in a batch file.

I wont to compare them like this:

N1=9
N2=3

And it should get 3/1, but i have no idea how to do this, or maybe its not possible.

Sorry if my english is a bit bad.

Any help would be apriciated.


See More: Batch file comparison problem.

Report •

#1
October 12, 2012 at 02:07:28
:: ===== script starts here ===============
::
:: silas.bat 2012-10-12 15:59:54.54
@echo off & setLocal enableDELAYedeXpansioN

set /a X=3
set /a Y=9

:: The Windows CMD shell can only do interger mat
:: so this works:

set /a Z=Y/X & echo !Z!

:: But this fails

set /a Z=X/Y & echo !Z!

goto :eof
::====== script ends here =================


====================================
Life is too important to be taken seriously.

M2


Report •

#2
October 12, 2012 at 03:11:03
I think you misunderstood.

I meant to get the ratio of the to numbers.


Report •

#3
October 12, 2012 at 03:17:06
Batch will not do ratio.


====================================
Life is too important to be taken seriously.

M2


Report •

Related Solutions

#4
October 12, 2012 at 03:19:03
Can you then do it in another programming language?

Like VBScript?


Report •

#5
October 12, 2012 at 04:12:40
I don't do VB but many of the helpers do.


====================================
Life is too important to be taken seriously.

M2


Report •

#6
October 12, 2012 at 17:48:24
"presentation" of the numbers is the main question. How are they aquired?
If you want commandline, this vbscript might do:
'==== begin vbscript snippet
wscript.stdout.writeline(wscript.arguments(0)/wscript.arguments(1))&":1"
'===== end vbscript snippet

Report •

#7
October 15, 2012 at 08:16:03
I have no idea how VBScript works, but the numbers come from to variables.

I have seen something where a batch works together with a VBScript to get a patch for a file.


Report •

#8
October 15, 2012 at 18:00:59
The vbscript that I posted uses commandline arguments. A batchfile could send the variables to the script using the commandline. Here is an example:

::===== begin batchscript test
set /p number1="first number: "
set /p number2="second number: "
> div.vbs echo wscript.stdout.write(wscript.arguments(0)/wscript.arguments(1))^&":1"
for /f %%a in ('div.vbs %number1% %number2%') do set ratio=%%a
echo %ratio%
::===== end batchscript

Again, the source of the two values to be compared has yet to be determined, so I just used "set /p" and prompted for them. This batchscript writes the vbscript each time it runs, but you could circumvent that if you wanted. Or, you could do away with the batch "wrapper" altogether and just use the vbscript.


Report •

#9
October 17, 2012 at 13:07:23
I'm interested in why you would want a script to reduce fractions, outside of homework-related reasons.

How To Ask Questions The Smart Way


Report •

Ask Question