Jump to content

Recommended Posts

Posted

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....

Posted

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)

 

Posted

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:

  Reveal hidden contents

 

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...