MattHiggs

(solved) Array not being set correctly

6 posts in this topic

#1 ·  Posted (edited)

Hello autoit scripters.

So I have a question, and while this something I haven't tried before, I would still think it would be pretty straight forward.  Below is some code that I have written which will read a file to an array, and I want to create a 2-dimensional array with the number of rows being equal to the number of items in the array divided by 4, and the number of columns equal to 4.  However, when I try to create the array in this way, when I actually try to assign values to it, autoit is telling me that the array itself is returning an error.  Thanks in advance:

#include <File.au3>
#include <Word.au3>
#include <Array.au3>

$array = FileReadToArray ( "C:\Users\whiggs\Documents\skills.txt" )
_ArrayDisplay ( $array )
Local $arr[Ceiling ( UBound ( $array ) / 4 )][4]
$hol = 0
For $i = 0 To UBound ( $array ) - 1 Step 4
    $arr[$hol][$i] = $array[$i]
    If @error Then
        SetError ( 0 )
        ExitLoop
    EndIf
    $arr[$hol][$i + 1] = $array[$i + 1]
    If @error Then
        SetError ( 0 )
        ExitLoop
    EndIf
    $arr[$hol][$i + 2] = $array[$i + 2]
    If @error Then
        SetError ( 0 )
        ExitLoop
    EndIf
    $arr[$hol][$i + 3] = $array[$i + 3]
    If @error Then
        SetError ( 0 )
        ExitLoop
    EndIf
    $hol += 1
Next

 

Edited by MattHiggs

Share this post


Link to post
Share on other sites



#2 ·  Posted

Hello. Share a sample of skills.txt

Input and expected output array.

Saludos

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)


It isn't exactly clear to me, what you are after ..

maybe try to work out something with this:

Local $i = 0
Local $s = 0
For $x = 1 To Ceiling(UBound($array) / 4) - 1
    Do
        $arr[$x][$i] = $array[$s]
        $i += 1
        $s += 1
    Until $i = 4
    $i = 0
Next

 

Edited by Deye

Share this post


Link to post
Share on other sites

#4 ·  Posted

I'm confused too... I think what you're trying to achieve.. could be done simpler.

Share this post


Link to post
Share on other sites

#5 ·  Posted

Yeah I did just end up doing something simpler.  The point of this was to use the content of skills.txt to create a table in a word document comprised of the contents.  However, skills.txt has only 27 lines of regular text, so that just creates a table with one column and 27 rows, which would look pretty stupid.  So I was trying to create a 2 dimensional array that would have 4 columns and however many number of rows would be necessary to hold the data stored in skills.txt.  However, I just modified skills.txt so that the Function which creates tables in word would create the table as I desired.  Sorry for the delay.  Today has been a very.....stressful.... day.

 

Share this post


Link to post
Share on other sites

#6 ·  Posted

Maybe you could also do like a list view display, so each time you run the script, it will give you the list view representation of Skills.txt.

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