Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8378129
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T15:51:22+00:00 2026-06-09T15:51:22+00:00

I am working on a short batch file program that accepts input and does

  • 0

I am working on a short batch file program that accepts input and does some simple math. It seems to work correctly for everything except the first echo. Here is the code:

set /p usercommand= "Input:"
if "%usercommand%" equ "done" (

set /p usertimeouthours= "Input Hours: "
echo (%usertimeouthours%)

set /p usertimeoutminutes= "Input Minutes: "
echo (%usertimeoutminutes%)

set /p usertimeoutseconds= "Input Seconds: "
echo (%usertimeoutseconds%)

set /a answer= %usertimeouthours%*3600+%usertimeoutminutes%*60+%usertimeoutseconds%
echo %answer%

goto end
) else (
echo finished
goto user
)
:end 

why does the first echo only output

(

my guess is something is wrong with my if statement, does anyone know how I should change it?

Thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T15:51:23+00:00Added an answer on June 9, 2026 at 3:51 pm

    Problem 1 – Normal vs Delayed expansion of variables
    Normal expansion using %var% occurs at parse time, and the entire IF statement is parsed all at once, including the contents within the parentheses. So something like echo (%usertimeouthours%) displays the value of USERTIMEOUTHOURS as it existed before the IF statement was executed (before SET /P set the value).

    The fix is to enable delayed expansion at the top using setlocal enableDelayedExpansion and use !var! instead of %var%. Delayed expansion occurs at execution time instead of parse time.

    Problem 2 – Unescaped special characters
    There are a number of characters that have special meaning and must be either escaped with ^ or quoted if you want the character to be treated as a string literal.

    One of the special characters is ). It will terminate any code block opened with ( unless it is escaped or quoted. You need to escape that character as ^) when you use it in your ECHO statements because those statements are within a parenthesized block of code.

    Simplification of your SET /A statement
    You do not need to expand variables when used in a SET /A computation. You can simply use the variable name without enclosing in percents or exclamations. This convenience only works with SET /A.

    @echo off
    setlocal enableDelayedExpansion
    set /p usercommand= "Input:"
    if "%usercommand%" equ "done" (
    
      set /p usertimeouthours= "Input Hours: "
      echo (!usertimeouthours!^)
    
      set /p usertimeoutminutes= "Input Minutes: "
      echo (!usertimeoutminutes!^)
    
      set /p usertimeoutseconds= "Input Seconds: "
      echo (!usertimeoutseconds!^)
    
      set /a answer= usertimeouthours*3600+usertimeoutminutes*60+usertimeoutseconds
      echo !answer!
    
      goto end
    ) else (
      echo finished
      goto user
    )
    :end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

The web seems a bit short on working examples for something that should be
So long story short, im working with some jquery tabs and im using this
I am working on a short java assignment that I have been set. The
This is a short example of an array that I am working with. Array
Long story short, I'm working on a .NET profiler that at one point gets
Long story short, I'm working with a library with a bug that causes a
I'm working on a project that requires batch processing of a large number of
In short, I'm working on a DurationPickerDialog that works similarly to how the DatePickerDialog
In short, I am currently working on a research problem for my university that
I´m currently working on a short SED script that needs to HTML-encode parts of

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.