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 6739431
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T11:29:20+00:00 2026-05-26T11:29:20+00:00

I’m attempting to use dynamic variables within Delayed Variable Expansion to represent other Dynamic

  • 0

I’m attempting to use dynamic variables within Delayed Variable Expansion to represent other Dynamic Variables. I’m running into some trouble. How can I get a dynamic variable’s value’s value if the dynamic variable’s value is another dynamic variable with it’s own value?

i.e. !valA! = %valB% = this

@ECHO OFF
SETLOCAL EnableExtensions EnableDelayedExpansion
...
...
FOR /F ... %%G IN (...) DO (
    SET _temp=%%~nG
    SET _file=!_temp:~0,-4!
    SET _cnt=0
    FOR /F ... %%L IN (...) DO (
        SET _temp=%%L
        SET _str=!_temp:*: =!
        SET /A _cnt+=1
        SET _temp=x!_file!!_cnt!
        IF DEFINED !_temp! (
            SET _temp=!%_temp%!
::
::_temp('s value) is _var('s value) is "xyz"
::Set new _temp to equal current _temp's "xyz"
::
            IF !_temp! NEQ !_str! (
                ECHO File Content Mismatch
            )
        ) ELSE (
            SET xvar=!_temp!
            SET !xvar!=!_str!
        )

    )
)
...
...
exit

Any help would be appreciated.

  • 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-05-26T11:29:20+00:00Added an answer on May 26, 2026 at 11:29 am

    Logically your failing code equates to

    setlocal enableDelayedExpansion
    (
      set VAR1=success
      set VAR2=VAR1
      set VAR3=!%VAR2%!
      echo VAR3=!VAR3!
    )
    

    As has already been pointed out in previous answers and comments, you can’t assign a value to VAR2 and then access the value using %VAR2% within the same code block because %VAR2% is expanded during the parsing phase of the code block, at which point the value is not what you want (probably undefined).

    But you need a second level of expansion in addition to !VAR2! to get the result you want. I know of three solutions.

    1) This solution works, but it is not recommended because it is slow.

    setlocal enableDelayedExpansion
    (
      set VAR1=success
      set VAR2=VAR1
      call set VAR3=%%!VAR2!%%
      echo VAR3=!VAR3!
    )
    

    Prior to the execution of the CALL, each %% is reduced to %, and !VAR2! becomes VAR1.
    Thus the called statement becomes set VAR3=%VAR1%, and the called statement is reparsed through the %var% expansion phase, so you get your desired result.

    BUT – CALL is relatively very expensive. When used in a loop it can cause severe performance degradation. jeb provides a good demonstration and explanation at CALL me, or better avoid call

    1a) There is a variation of the CALL solution where you call a :LABELed subroutine. Because the subroutine is parsed after the call, you can simply use set VAR3=!%VAR2%!. But again, this uses CALL so it is relatively slow and not recommended.

    2) This general solution works, and is MUCH faster in comparison. It uses a FOR variable for the second level of expansion. This is the recommended solution.

    setlocal enableDelayedExpansion
    (
      set VAR1=success
      set VAR2=VAR1
      for /f %%A in ("!VAR2!") do set VAR3=!%%A!
      echo VAR3=!VAR3!
    )
    

    3) If the value of VAR1 is known to be an integer, then there is a special case solution using SET /A

    setlocal enableDelayedExpansion
    (
      set VAR1=999
      set VAR2=VAR1
      set /a VAR3=!VAR2!
      echo VAR3=!VAR3!
    )
    

    The SET /A command has its own built in expansion of variables that takes place after delayed expansion, and no punctuation is needed.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a French site that I want to parse, but am running into
I am currently running into a problem where an element is coming back from
I have just tried to save a simple *.rtf file with some websites and
For some reason, after submitting a string like this Jack’s Spindle from a text
I am trying to understand how to use SyndicationItem to display feed which is
this is what i have right now Drawing an RSS feed into the php,
I want use html5's new tag to play a wav file (currently only supported
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I'm trying to use string.replace('’','') to replace the dreaded weird single-quote character: ’ (aka

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.