Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @ECHO OFF
- REM :: Rem out @ECHO OFF to see the demo step by step.
- MODE 1000
- setlocal enabledelayedexpansion
- REM :: To define string Values, enclose the string in Doubleqoutes: "text here" and Expand using %%~a within the For loop to
- REM :: strip the Doublequotes. Same is recommended for population of arrays with Filepaths.
- CALL :define example e_M 2 4 6 8 10 12 14 16 18 20
- CALL :display example !e_M!
- CALL :define demo d_M 1 3 5 7 9 11 13 15 17 19 21 23 25 27 29
- CALL :display demo !d_M!
- pause
- exit
- :define
- REM - Assigns parameters 3+ to array index 0 onwards
- REM - Call :define <arrayname> <MaxValueVar> <index0Val> ~ <indexLastVal>
- REM - Strip Array name and MaxValue Variable name from processing
- Set count=-2
- FOR %%a in (%*) DO (
- Set "%1[!count!]=%%a"
- Set /a count+=1
- )
- REM - Establishes Array Range from Index 0-Last, Accounting for Index 0
- Set /a %2=!count!-1
- GOTO :EOF
- :display
- REM - Loops through Index 0-Last.
- REM - Call :display <arrayname> <MaxValueVar>
- REM - This type of For loop can be used to Display or test Index values - Or - perform actions using Array values.
- For /L %%a IN (0,1,%2) DO (
- ECHO %1[%%a] = !%1[%%a]!
- )
- REM - Account for Index 0 in Array range.
- Set /a ttl=1 + %2
- ECHO.
- ECHO %1 Contains [%ttl%] Elements
- ECHO.
- GOTO :EOF
- REM :: To access an individual array elements value, expand it as follows: !%ArrayName%[IndexNumber]!
- REM :: To modify an individual array elements value, Set it as follows: Set "ArrayName[IndexNumber]=Value"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement