There's no such thing as a stupid question, but they're the easiest to answer.
JoinTour
Login
 
Tag Cloud
black screen blue screen blue screen of death boot computer connection crash css dell display driver drivers error excel firefox firefox 3 game hard drive internet internet explorer itunes laptop lcd linux malware monitor network networking nvidia outlook outlook 2003 outlook express partition password printer problem ram router slow software sound sprtcmd.exe trojan usb video virus vista windows windows xp wireless
Software Development
Search
Search in:
 
Advanced Search
Tech Support Guy Forums > Software & Hardware > Software Development >
Simple BATCH math


HELLO AND WELCOME! Before you can post your question, you'll have to register -- it's completely free! Click here to join today! We highly recommend that you print a copy of our Guide for New Members. Enjoy!

Closed Thread
 
Thread Tools
madd74's Avatar
Computer Specs
Senior Member with 211 posts.
 
Join Date: Nov 2003
Location: Des Moines, IA
Experience: Advanced
18-Jul-2008, 05:30 PM #1
Simple BATCH math
I am writing a .BAT file for my job function. It is extremely nice minus one simple thing I am attempting to do, math. How would one write the following for a BAT file?

--------------------
set /p hour= Number of hours on hold:
if '%hour%' =< 1 set gramtime="hour"
if '%hour%' =< 1 set gramtime="hours"
echo You are on hold for %hour% %gramtime%
--------------------

Everything is working except "gramtime" is not being set to anything because this gives an error message that "= was unexpected at this time" and the .BAT exits. I also attempted

--------------------
@echo off
set hour=
echo 1
set /p hour= Number of hours on hold:
echo 2
if '%hour%'=="1" goto justhour
echo 3
set gramtime=hours
echo 4
goto cont
echo 5
:justhour
echo 6
set gramtime=hour
echo 7
goto cont
echo 8
:cont
echo You are on hold for %hour% %gramtime%
--------------------

Now the thing I noticed with this, is that the ECHO display 1,2,3,4 each time, meaning the GOTO is not being triggered when I would put 1 in as my input. I do not ever see 5 or 8 (because I never will ) and I do not ever see 6 (even though my "You are on hold for..." would display 1 if I entered in 1)

So my output is always "You are on hold for X hours"

Thanks in advance for any help!
__________________
madd says check out Madd's World - Red Mage of the Net (madd74.com) or chat with me and friends live! or visit madd on myspace
Squashman's Avatar
Distinguished Member with 12,699 posts.
 
Join Date: Apr 2003
Location: 1265 Lombardi Ave
18-Jul-2008, 07:12 PM #2
Code:
Two new switches have been added to the SET command:

    SET /A expression
    SET /P variable=[promptString]

The /A switch specifies that the string to the right of the equal sign
is a numerical expression that is evaluated.  The expression evaluator
is pretty simple and supports the following operations, in decreasing
order of precedence:

    ()                  - grouping
    ! ~ -               - unary operators
    * / %               - arithmetic operators
    + -                 - arithmetic operators
    << >>               - logical shift
    &                   - bitwise and
    ^                   - bitwise exclusive or
    |                   - bitwise or
    = *= /= %= += -=    - assignment
      &= ^= |= <<= >>=
    ,                   - expression separator
Closed Thread

Tags
bat, batch, batch math

THIS THREAD HAS EXPIRED.
Are you having the same problem? We have volunteers ready to answer your question, but first you'll have to join for free. Need help getting started? Check out our Welcome Guide.


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
WELCOME TO TECH SUPPORT GUY! Are you looking for the solution to your computer problem? Join our site today to ask your question -- for free! Our site is run completely by volunteers who help people like you solve computer problems. See our Welcome Guide to get started.



Thread Tools


You Are Using:
Server ID
Advertisements do not imply our endorsement of that product or service.
All times are GMT -4. The time now is 07:13 AM.
Copyright © 1996 - 2008 TechGuy, Inc. All rights reserved.
Powered by vBulletin, Copyright © 2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Powered by Cermak Technologies, Inc.