ETverde 0 Posted January 8, 2022 Share Posted January 8, 2022 hi all i have a code reading some numebers into an array like 0132 0123 0111 0222 0333 so... i need it to update 4 vars exemple $n1 = $array{1} (1st number) $n2 = $array{1} (2nd number) $n3 = $array{1} (3rd number) $ng4 = $array{1} (4tnumber) to use on a loop reading line per line of this array but... i hav no idea of how do that.... Link to post Share on other sites
Subz 826 Posted January 8, 2022 Share Posted January 8, 2022 Unsure if you meant something like: #include <Array.au3> Local $sNumbers = "0132" & @CRLF & _ "0123" & @CRLF & _ "0111" & @CRLF & _ "0222" & @CRLF & _ "0333" ;~ Split the string into seperate rows, using @CRLF Local $aNumbers = StringSplit($sNumbers, @CRLF, 3) ;~ Declare your variables Local $aVar1[0], $aVar2[0], $aVar3[0], $aVar4[0] Local $aNumber ;~ Loop through each row For $i = 0 To UBound($aNumbers) - 1 ;~ Split the row number, using no character (splits each number) $aNumber = StringSplit($aNumbers[$i], "", 2) ;~ Add the first number to variable 1 _ArrayAdd($aVar1, $aNumber[0]) ;~ Add the second number to variable 2 _ArrayAdd($aVar2, $aNumber[1]) ;~ Add the third number to variable 3 _ArrayAdd($aVar3, $aNumber[2]) ;~ Add the fourth number to variable 4 _ArrayAdd($aVar4, $aNumber[3]) Next ;~ Display the results _ArrayDisplay($aNumbers) _ArrayDisplay($aVar1) _ArrayDisplay($aVar2) _ArrayDisplay($aVar3) _ArrayDisplay($aVar4) Link to post Share on other sites
junkew 478 Posted January 9, 2022 Share Posted January 9, 2022 $n1 = $array[1] use square brackets Read help on assign function if it needs dynamic assignment FAQ 31 How to click some elements, FAQ 40 Test automation with AutoIt, Multithreading CLR .NET Powershell CMDLets Link to post Share on other sites
water 2,720 Posted January 9, 2022 Share Posted January 9, 2022 On the other hand: Why do you need to assign the array values to variables? You could simply access the array values directly. Makes the script simpler and easier to read My UDFs and Tutorials: Spoiler UDFs:Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsOutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - WikiOutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - DownloadOutlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - WikiPowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - WikiTask Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs:Excel - Example Scripts - WikiWord - Wiki Tutorials:ADO - WikiWebDriver - Wiki Link to post Share on other sites
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now