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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T18:39:37+00:00 2026-06-04T18:39:37+00:00

I have two elements in my array list in my program. How can I

  • 0

I have two elements in my array list in my program. How can I assign a variable to equal one of the elements?

Here’s the code:

@echo off
setlocal enabledelayedexpansion
set /p string=
for /l %%a in (0,1,1000) do if not "!String:~%%a,1!"=="" set /a length=%%a+1
set i=0
:input
set str=%string:~0,1%
if "%str%"=="M" set array[i]=1000
if "%str%"=="D" set array[i]=500
if "%str%"=="C" set array[i]=100
if "%str%"=="L" set array[i]=50
if "%str%"=="X" set array[i]=10
if "%str%"=="I" set array[i]=1
set string=%string:~1%
set /a i=i+1
if %i%==%length% goto logic
goto input
:logic

I really though there was a standard way of doing this.

  • 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-04T18:39:38+00:00Added an answer on June 4, 2026 at 6:39 pm

    The main problem is that your code doesn’t create any batch-array.
    Your code create only one variable named array[i], but I suppose you want to create an array with:

    array[0]=1000
    array[1]=500
    

    Then you need something like

    setlocal EnableDelayedExpansion
    set i=0
    :inputLoop
    set "str=%string:~0,1%"
    if "%str%"=="M" set array[%i%]=1000
    if "%str%"=="D" set array[%i%]=500
    if "%str%"=="C" set array[%i%]=100
    if "%str%"=="L" set array[%i%]=50
    if "%str%"=="X" set array[%i%]=10
    if "%str%"=="I" set array[%i%]=1
    set "string=%string:~1%"
    set /a i+=1
    if NOT %i%==%length% goto :inputLoop
    
    :logic
    rem ** logic begins
    for /L %%n in (1 1 %i%) do (
       echo !array[%%n]!
       set /a value=array[%%n]
    )
    

    And in the logic part you can see how to access an array element.

    Btw. Your strlen function is a little bit slow, it could be faster with a binary search.
    How to count the characters in a string with Batch?

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

Sidebar

Related Questions

I have an array(list?) in ruby: allRows = [start,one,two,start,three,four,start,five,six,seven,eight,start,nine,ten] I need to run a
I have two lists with 8 list elements within each one. I would like
I have a simple simulated array with two elements: bowl["fruit"] = "apple"; bowl["nuts"] =
I have two path elements. For the sake of description lets just say one
I have two div -elements, the top one has the height of 40% and
I have two snippets of code that tries to convert a float list to
Let's say I have a vector (array, list, whatever...) V of N elements, let's
I have a code that fetches a list from DB. Using that returned array
I have two arrays (a and b) with n integer elements in the range
I have a two dimensional JSON array where each element contains several attributes. The

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.