sonic208

array incorrect number of subscripts ? works sometimes sometimes not ?

7 posts in this topic

#1 ·  Posted (edited)

hey guys, 

im using a shuffle function to shuffle the lines read in a textdocument . sometimes i get the number of subscripts error, sometimes not although i dont change the script. where is the mistake ?

#include <Array.au3>
#include <File.au3>
start()

Func start() 
FileOpen("zuueberpruefendenummern.txt")

Global $zeilen = _FileCountLines( "C:\users\edon\desktop\registrierungsueberpruefer v1.1\zuueberpruefendenummern.txt")
Dim $in[$zeilen]


For $s = 0 to ($zeilen-1)

    $in[$s] =FileReadLine("zuueberpruefendenummern.txt",($s+1))

Next

FileClose("zuueberpruefendenummern.txt")

$out = _Shuffle($in)

EndFunc



Func _Shuffle($aIn)
    Dim $aOut[UBound($aIn)]

    Dim $iRand
    Dim $iNext = 0

    While UBound($aIn) > 1
        $iRand = Random(0,UBound($aIn)-1,1)

        $aOut[$iNext] = $aIn[$iRand] 
        $iNext += 1

        _ArrayDelete($aIn,$iRand)
    WEnd

    $aOut[$iNext] = $aIn[0]

    Return $aOut
EndFunc

the error points at the line where the $ain[$iRand] value gets stored to the $aout array... 

Edited by sonic208

Share this post


Link to post
Share on other sites



#2 ·  Posted

possibly, its coming up with an error when reading the lines in the FileReadLine. Try put an "if @error then return: or maybe in the _shuffle func put "If IsArray($aIn) then" or something like that.

1 person likes this

Share this post


Link to post
Share on other sites

#3 ·  Posted

Nothing jumping out at me at first glance, but I am curious...did you see or try the _ArrayShuffle function in the UDF?  If so, did it not handle your needs?

Share this post


Link to post
Share on other sites

#4 ·  Posted

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

Global $in

_FileReadToArray("C:\users\edon\desktop\registrierungsueberpruefer v1.1\zuueberpruefendenummern.txt",$in,0)
_ArrayShuffle($in)
_ArrayDisplay($in)
 

Share this post


Link to post
Share on other sites

#5 ·  Posted

so the first problem was the path because it didnt work at all . i  changed it now and it works after the second start.  

this is not such a big problem, but its very interesting for me why it wont work at the first start and give me the error. ill investigate more in this and try to get more information when it occurs and when not, now ill try if the error occurs when i build it to an exe

Share this post


Link to post
Share on other sites

#6 ·  Posted

1 minute ago, LeCarre said:

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

Global $in

_FileReadToArray("C:\users\edon\desktop\registrierungsueberpruefer v1.1\zuueberpruefendenummern.txt",$in,0)
_ArrayShuffle($in)
_ArrayDisplay($in)
 

so i can use these 3 lines instead of that shuffle function? are you sure ? thxxxx !

Share this post


Link to post
Share on other sites

#7 ·  Posted

Glad to help :)

1 person likes this

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