Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @REM this script is only to demonstrate the mechanics of Comparing Arrays and Shifting Arrays.
- @ECHO OFF
- SETLOCAL ENABLEDELAYEDEXPANSION
- Set Max=5
- Set /p "Max=[Enter Array Range:]
- REM - Account for Element 0:
- Set /a Max-=1
- :main
- Set "Val=0"
- cls
- REM - Use for /L loop to assign values to array elements using Max as the total number of elements.
- For /L %%a in (0,1,!Max!) DO (
- Set /p "Array[!Val!]=[Enter Array[!Val!] Value:]"
- If not defined Array[!Val!] (
- goto main
- )
- Set /a Val+=1
- )
- REM - Call function to display values assigned to array elements
- CALL :Display
- pause
- REM - Tacks ann Element onto the end of the Array
- REM - User inputs the New Elements Value.
- REM - For Loop creats an Array for comparison
- REM - The example Clones the Original Array and shifts the the Elements using a tmp offset Variable - !Val_O!
- REM - Array value Set has to be Called as a Function, It will not Set the Value withing the Loop.
- :append
- Set /a Max+=1
- cls
- Set cvo=0
- For /L %%a in (0,1,!Max!) DO (
- Set cva=%%a
- Call :Increment
- IF NOT DEFINED Array[!cvo!] (
- Set /p comp[%%a]=[Enter comp[!cvo!] Value:]
- )
- IF !comp[%%a]!==!comp[%Max%]! (
- Set /p Array[!Max!]=[Enter Array[!Max!] Value:]
- Goto Comparison
- )
- )
- REM - For /L loop displays the values Assigned to each Element in the Comparison Array
- :Comparison
- CALL :Display
- For /L %%a in (0,1,!Max!) DO (
- ECHO comp[%%a] = !comp[%%a]!
- )
- pause
- cls
- REM - For /L Loop Compares the Array and Substitutes Values If Arrays don't Match.
- REM - Action taken is for Demonstration Purposes.
- REM - the Action Demonstrated executes shifting the values of the Arrays Elements using the Clone/Offset Array.
- :process
- For /L %%a in (0,1,!Max!) DO (
- IF NOT !Array[%%a]!==!Comp[%%a]! (
- ECHO Array[%%a] !Array[%%a]! NEQ !Comp[%%a]! Comp[%%a]
- ECHO Values Exchanged for Array[%%a]
- Set "Array[%%a]=!comp[%%a]!"
- ) else (
- ECHO Values Matched for Array[%%a]
- )
- )
- pause
- CALL :Display
- :end
- Pause
- EXIT
- :Increment
- Set /a cvo+=1
- Set comp[%cva%]=!Array[%cvo%]!
- GOTO :EOF
- GOTO :EOF
- REM - Function that uses For /L loop to display the values of all currently assigned Elements.
- :Display
- cls
- For /L %%a in (0,1,!Max!) DO (
- ECHO array[%%a] = !array[%%a]!
- )
- GOTO :EOF
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement