Jump to content

Help to turn variables into.... more variables....rsrsrsrs


Recommended Posts

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

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

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 2021-11-10 - Version 1.6.0.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (NEW 2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (NEW 2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (2019-12-03 - Version 1.5.1.0) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...