How do I use basic batch math commands to come up with decimal answers?

前端 未结 4 697
名媛妹妹
名媛妹妹 2021-01-15 22:10

I am making a batch file so that I just tell it what kind of formula I need to use and it tells me what variables I need to input. Right now, I am coding it so that it will

4条回答
  •  误落风尘
    2021-01-15 22:24

    Use this one line basic script

        Execute "Wscript.echo " & wscript.Arguments(0)
    

    To use

        cscript //nologo script.vbs "2.5*2.5"
    

    How to use

    C:\Users\User>cscript //nologo "C:\Users\User\Desktop\New Text Document.vbs" "2.5*2.5"
    6.25
    

    The second line is how to use the program you just wrote as a command prompt command. cscript //nologo "c:\somefolder\script.vbs" "%TriangleB% * %TriangleH% / 2". Note the expression must be enclosed with quotes if it contains spaces. To put into a command prompt variable use for command. for /f "delims=" %%A in ('cscript //nologo c:\somefolder\script.vbs "%TriangleB% * %TriangleH% / 2"') Do Set Result=%%A

    So

    C:\Users\User>Set TriangleB=5.5
    
    C:\Users\User>Set TriangleH=3.5
    
    C:\Users\User>for /f "delims=" %A in ('cscript //nologo "C:\Users\User\Desktop\New Text Document.vbs" "%TriangleB% * %TriangleH% / 2"') Do Set Result=%A
    
    C:\Users\David Candy>Set Result=9.625
    

    Remember in a batch use %%A and interactively (ie typing) use %A

    To do the same thing in an HTA (a web page renamed to .hta which makes it act like a program)

    
        
            
        
        
    
    

    And in vbscript only

     Wscript.echo InputBox("Height") * Inputbox("width") /2
    

提交回复
热议问题