Jump to content

Initialization of arrays...


Recommended Posts

Why in the hell does it keep the 0 after I set this:

$arCharactersTemp[1][0]="A"

returns

A0

Seems like a waste to have to do a StringTrimRight for each one... I tried searching but I had no idea what to look for :lmao:

"I thoroughly disapprove of duels. If a man should challenge me, I would take him kindly and forgivingly by the hand and lead him to a quiet place and kill him." - Mark TwainPatient: "It hurts when I do $var_"Doctor: "Don't do $var_" - Lar.
Link to comment
Share on other sites

Not at all.

Dim $arCharactersTemp[63][2]

$arCharactersTemp[1][0]="A"
$arCharactersTemp[1][1]="0,-1;-1,0;-1,-1;-7,0;-7,-1;"

Const $arCharacters = $arCharactersTemp

$Test = "0,-1;-1,0;-1,-1;-7,0;-7,-1;"
$String = ""

For $x = 1 to UBound($arCharacters) - 1
   If $arCharacters[$x][1] = $Test Then
      $String = $String & $arCharacters[$x][0]
   EndIf
Next   

MsgBox("","", $String)

Thought it was a simple matter, no idea I had to post a demo.

Edited by Insolence
"I thoroughly disapprove of duels. If a man should challenge me, I would take him kindly and forgivingly by the hand and lead him to a quiet place and kill him." - Mark TwainPatient: "It hurts when I do $var_"Doctor: "Don't do $var_" - Lar.
Link to comment
Share on other sites

Use == to force a string comparison. By default, an unintialized variable (Or array element) is a number 0 with string representation "". The If statement is performing a numerical comparison between 0 (Unitialized array element's default value) and a string, and since strings are 0 when converted to numbers (In this case), the condition is always true, so you are appending the contents every iteration of the loop.

This isn't an AutoIt bug but rather its normal behavior for the last several months if not since the beginning.

Link to comment
Share on other sites

That's nuts.

Thanks.

"I thoroughly disapprove of duels. If a man should challenge me, I would take him kindly and forgivingly by the hand and lead him to a quiet place and kill him." - Mark TwainPatient: "It hurts when I do $var_"Doctor: "Don't do $var_" - Lar.
Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...