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

  • SEARCH
  • Home
  • 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 8420439
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T02:53:14+00:00 2026-06-10T02:53:14+00:00

I have a batch script but for whatever reason once a value is set

  • 0

I have a batch script but for whatever reason once a value is set in my foor loop it persists and doesn’t update. My values:’totalTime’ and ‘totalHours’ in my for loop are always the same value of the first time ‘converttime was called. I have verified that my ‘converttime’ function is accurately getting the right values but I am not sure how to get the values to change in my for loop.

My code looks like this:

@echo off

set duration=01:25:45

call :converttime %duration%

set /A duration=%totalHours%+%totalMins%

FOR /F "tokens=2 delims=#" %%i IN (subtitle.txt) DO (
    call :converttime %%i
    set /A totalTime=%totalMins%+%totalhours%
    echo %totalTime%
)
endlocal
goto :eof

:converttime
set mytime=%1
set hour=%mytime:~0,2%
set minute=%mytime:~3,2%
set seconds=%mytime:~6,7%

if NOT "%minute%"=="" (
    SET /A totalMins=%minute%*60000
)

if NOT "%hour%"=="~0,2" (
    set /A totalhours=%hour%*3600000    
)

The output is:

4500000
4500000
4500000
4500000
4500000
4500000

When it should be something like:

2500000
3520000
1450000

Any Ideas??

  • 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-10T02:53:15+00:00Added an answer on June 10, 2026 at 2:53 am

    I got it. I just needed to use the ‘setLocal’ command. and surround my variables with ! instead of %

    My completed code looks like this:

    @echo off
    
    set duration=01:25:45
    call :converttime %duration%
    
    set /A duration=%totalHours%+%totalMins%
    setlocal ENABLEDELAYEDEXPANSION 
    FOR /F "tokens=2 delims=#" %%i IN (subtitle.txt) DO (
        call :converttime %%i
        set /A totalTime=!totalMins!+!totalhours!
        echo !totalTime!
    )
    ENDLOCAL
    goto :eof
    
    :converttime
    set mytime=%1
    set hour=%mytime:~0,2%
    set minute=%mytime:~3,2%
    set seconds=%mytime:~6,7%
    
    if NOT "%minute%"=="" (
        SET /A totalMins=%minute%*60000
    )
    
    if NOT "%hour%"=="~0,2" (
        set /A totalhours=%hour%*3600000    
    )
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Here's my configuration: I have a re-runnable batch script that I use to update
i have written a batch script but it still ask me for a password.
I have a batch script that outputs a file, and I'm trying to ensure
I have a batch script that looks like this: Test.bat @echo off :: Starts
I have a batch script that calls a process and currently it waits for
I have a batch script, I think my issue has to do with parentheses
I have the following batch script to print all the folders under a directory
I have one windows batch script where I am calling two other batch script.
I have a Batch file which will call a Powershell Script : BATCH FILE
I have a script located at /tmp/My Batch Script Files/Processing How would I run

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.