Sign in to follow this  
Followers 0
weasel127

Help with arrays

4 posts in this topic

I'm not sure how to properly use an array. What I'm trying to do is string split a very large string, then add up each 3 of them and store them to another variable. Example: String 7.2.8.12.9.2.4.2.6 will be changed to (7+2+8) , (12+9+2) , (4+2+6) which will be 17, 23, and 12. This info will be stored to a variable $var[1] = 17, $var[2] = 23, and $var[3] = 12.

So far this is my script but I keep on getting errors with the arrays.

Local $_x
Dim $val[$_x]     ;I don't know how to declare the variables here         


$str = StringSplit("6.3.8.2.29.2.2.5.9.3.79.4.5.774.3",".")   ; (the acutal string is longer)

;MsgBox(0,"a",$string1[1])
;$str = StringSplit($string1,".")
MsgBox(0,"a",$str[1])

For $n = 2 to $str[0]
    $_x = $_x + 1
        $val[$_x] = ($str[$n] + $str[($n + 1)] + $str[($n + 2)])     ; $val is where the output is supposed to be stored
        $n = $n + 2
    MsgBox(0,"a",$str[$n])
Next

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

#include <array.au3>
Dim $aValue[1], $nAddArray
$aNStr = StringSplit("7.2.8.12.9.2.4.2.6",".")
$nModCheck = Int(UBound($aNStr) - 1)
If Mod($nModCheck, 3) Then
    MsgBox(16, 'Error', 'The sum of the array is not divisible by 3')
    Exit
EndIf
ReDim $aValue[($nModCheck / 3) + 1]
For $iCC = 1 To UBound($aNStr) - 1 Step 3
    $nAddArray += 1
    $aValue[$nAddArray] = Number($aNStr[$iCC])
    For $xCC = 1 To 2
        $aValue[$nAddArray] += Number($aNStr[$iCC + $xCC])
    Next
Next
_ArrayDisplay($aValue, '')

Edited by SmOke_N

[center]Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.[/center]

Share this post


Link to post
Share on other sites

Thank you very much, this is exactly what I needed.

Share this post


Link to post
Share on other sites

Thank you very much, this is exactly what I needed.

Your welcome... good of example of what trying and showing you tried gets you, and explaining exactly (with the exception it has to move every 3 characters specifically (got that from your example though)) what you need gets you... A solution you don't have to wait hours / days / weeks / or never for :).

[center]Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.[/center]

Share this post


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
Sign in to follow this  
Followers 0