Sign in to follow this  
Followers 0
nitekram

two dimension array - setting values with for/next

9 posts in this topic

OK - call me stupid , but I cannot figure out how to make this work

$aPlayersHand[0][0] = $iCard[0]

$aPlayersHand[0][1] = $iCard[1]

$aPlayersHand[1][0] = $iCard[2]

$aPlayersHand[1][1] = $iCard[3]

$aPlayersHand[2][0] = $iCard[4]

$aPlayersHand[2][1] = $iCard[5]

$aPlayersHand[3][0] = $iCard[6]

$aPlayersHand[3][1] = $iCard[7]

$aPlayersHand[4][0] = $iCard[8]

$aPlayersHand[4][1] = $iCard[9]

$aPlayersHand[5][0] = $iCard[10]

$aPlayersHand[5][1] = $iCard[11]

$aPlayersHand[6][0] = $iCard[12]

$aPlayersHand[6][1] = $iCard[13]

I need this to turn into a For/Next loop - any help?


All by me:

"Sometimes you have to go back to where you started, to get to where you want to go." 

"Everybody catches up with everyone, eventually" 

"As you teach others, you are really teaching yourself."

From my dad

"Do not worry about yesterday, as the only thing that you can control is tomorrow."

 

WindowsError.gif

WIKI | Tabs; | Arrays; | Strings | Wiki Arrays | How to ask a Question | Forum Search | FAQ | Tutorials | Original FAQ | ONLINE HELP | UDF's Wiki | AutoIt PDF

AutoIt Snippets | Multple Guis | Interrupting a running function | Another Send

StringRegExp | StringRegExp Help | RegEXTester | REG TUTOR | Reg TUTOT 2

AutoItSetOption | Macros | AutoIt Snippets | Wrapper | Autoit  Docs

SCITE | SciteJump | BB | MyTopics | Programming | UDFs | AutoIt 123 | UDFs Form | UDF

Learning to script | Tutorials | Documentation | IE.AU3 | Games? | FreeSoftware | Path_Online | Core Language

Programming Tips

Excel Changes

ControlHover.UDF

GDI_Plus

Draw_On_Screen

GDI Basics

GDI_More_Basics

GDI Rotate

GDI Graph

GDI  CheckExistingItems

GDI Trajectory

Replace $ghGDIPDll with $__g_hGDIPDll

DLL 101?

Array via Object

GDI Swimlane

GDI Plus French 101 Site

GDI Examples UEZ

GDI Basic Clock

GDI Detection

Ternary operator

Share this post


Link to post
Share on other sites



$num_elements = 14

If Mod($num_elements,2) > 0 Then
    MsgBox(0,"","$iCard must contain an even number of elements")
    Exit
EndIf

Dim $iCard[$num_elements]
Dim $aPlayersHand[$num_elements/2][2]

$aPlayersHand[0][0] = $iCard[0]
$aPlayersHand[0][1] = $iCard[1]
$aPlayersHand[1][0] = $iCard[2]
$aPlayersHand[1][1] = $iCard[3]
$aPlayersHand[2][0] = $iCard[4]
$aPlayersHand[2][1] = $iCard[5]
$aPlayersHand[3][0] = $iCard[6]
$aPlayersHand[3][1] = $iCard[7]
$aPlayersHand[4][0] = $iCard[8]
$aPlayersHand[4][1] = $iCard[9]
$aPlayersHand[5][0] = $iCard[10]
$aPlayersHand[5][1] = $iCard[11]
$aPlayersHand[6][0] = $iCard[12]
$aPlayersHand[6][1] = $iCard[13]

$count = 0
For $X = 0 to $num_elements-1 Step 2
    $aPlayersHand[$count][0] = $iCard[$X]
    $aPlayersHand[$count][1] = $iCard[$X+1]
    $count += 1
Next

Share this post


Link to post
Share on other sites

OK - call me stupid , but I cannot figure out how to make this work

$aPlayersHand[0][0] = $iCard[0]

$aPlayersHand[0][1] = $iCard[1]

$aPlayersHand[1][0] = $iCard[2]

$aPlayersHand[1][1] = $iCard[3]

$aPlayersHand[2][0] = $iCard[4]

$aPlayersHand[2][1] = $iCard[5]

$aPlayersHand[3][0] = $iCard[6]

$aPlayersHand[3][1] = $iCard[7]

$aPlayersHand[4][0] = $iCard[8]

$aPlayersHand[4][1] = $iCard[9]

$aPlayersHand[5][0] = $iCard[10]

$aPlayersHand[5][1] = $iCard[11]

$aPlayersHand[6][0] = $iCard[12]

$aPlayersHand[6][1] = $iCard[13]

I need this to turn into a For/Next loop - any help?

Dim $aPlayersHand[7][2]
Dim $iCard[14]
$COUNT = 0
For $I = 0 To 6
    For $J = 0 To 1
        $aPlayersHand[$I][$J] = $iCard[$COUNT]
        $COUNT += 1
    Next
Next

When the words fail... music speaks

Share this post


Link to post
Share on other sites

Thanks for the quick reply

I get the following when trying to access the array, yet i am still trying to get this

==> Array variable has incorrect number of subscripts or subscript dimension range exceeded.:

Here is the code

For $X = 0 to $TotalPlayers * 2 -1 Step 2
    $aPlayersHand[$count][0] = $iCard[$X]
    $aPlayersHand[$count][1] = $iCard[$X+1]
    $count += 1
    ConsoleWrite($count & $aPlayersHand[$count][0] & '  ' & $aPlayersHand[$count][1] & @CRLF)
Next

All by me:

"Sometimes you have to go back to where you started, to get to where you want to go." 

"Everybody catches up with everyone, eventually" 

"As you teach others, you are really teaching yourself."

From my dad

"Do not worry about yesterday, as the only thing that you can control is tomorrow."

 

WindowsError.gif

WIKI | Tabs; | Arrays; | Strings | Wiki Arrays | How to ask a Question | Forum Search | FAQ | Tutorials | Original FAQ | ONLINE HELP | UDF's Wiki | AutoIt PDF

AutoIt Snippets | Multple Guis | Interrupting a running function | Another Send

StringRegExp | StringRegExp Help | RegEXTester | REG TUTOR | Reg TUTOT 2

AutoItSetOption | Macros | AutoIt Snippets | Wrapper | Autoit  Docs

SCITE | SciteJump | BB | MyTopics | Programming | UDFs | AutoIt 123 | UDFs Form | UDF

Learning to script | Tutorials | Documentation | IE.AU3 | Games? | FreeSoftware | Path_Online | Core Language

Programming Tips

Excel Changes

ControlHover.UDF

GDI_Plus

Draw_On_Screen

GDI Basics

GDI_More_Basics

GDI Rotate

GDI Graph

GDI  CheckExistingItems

GDI Trajectory

Replace $ghGDIPDll with $__g_hGDIPDll

DLL 101?

Array via Object

GDI Swimlane

GDI Plus French 101 Site

GDI Examples UEZ

GDI Basic Clock

GDI Detection

Ternary operator

Share this post


Link to post
Share on other sites

Maybe:

For $X = 0 to ($TotalPlayers * 2) -1 Step 2

Share this post


Link to post
Share on other sites

Maybe:

For $X = 0 to ($TotalPlayers * 2) -1 Step 2

OK that did not work, so I tested further and found that the data is not populating right

For $X = 0 to ($TotalPlayers * 2) -1 Step 2
    $aPlayersHand[$count][0] = $iCard[$X]
    $aPlayersHand[$count][1] = $iCard[$X+1]
    $count += 1
    ConsoleWrite($count & ' hand = ' & $aPlayersHand[$count][0] & '  ' & $aPlayersHand[$count][1] & @CRLF)
    ConsoleWrite($count & '           hand = ' & $iCard[$X] & '  ' & $iCard[$X+1] & @CRLF)
Next

the $iCard[$X] and $iCard[$X+1] has data but not $aPlayersHand[$count][0] or $aPlayersHand[$count][1]


All by me:

"Sometimes you have to go back to where you started, to get to where you want to go." 

"Everybody catches up with everyone, eventually" 

"As you teach others, you are really teaching yourself."

From my dad

"Do not worry about yesterday, as the only thing that you can control is tomorrow."

 

WindowsError.gif

WIKI | Tabs; | Arrays; | Strings | Wiki Arrays | How to ask a Question | Forum Search | FAQ | Tutorials | Original FAQ | ONLINE HELP | UDF's Wiki | AutoIt PDF

AutoIt Snippets | Multple Guis | Interrupting a running function | Another Send

StringRegExp | StringRegExp Help | RegEXTester | REG TUTOR | Reg TUTOT 2

AutoItSetOption | Macros | AutoIt Snippets | Wrapper | Autoit  Docs

SCITE | SciteJump | BB | MyTopics | Programming | UDFs | AutoIt 123 | UDFs Form | UDF

Learning to script | Tutorials | Documentation | IE.AU3 | Games? | FreeSoftware | Path_Online | Core Language

Programming Tips

Excel Changes

ControlHover.UDF

GDI_Plus

Draw_On_Screen

GDI Basics

GDI_More_Basics

GDI Rotate

GDI Graph

GDI  CheckExistingItems

GDI Trajectory

Replace $ghGDIPDll with $__g_hGDIPDll

DLL 101?

Array via Object

GDI Swimlane

GDI Plus French 101 Site

GDI Examples UEZ

GDI Basic Clock

GDI Detection

Ternary operator

Share this post


Link to post
Share on other sites

OK that did not work, so I tested further and found that the data is not populating right

For $X = 0 to ($TotalPlayers * 2) -1 Step 2
    $aPlayersHand[$count][0] = $iCard[$X]
    $aPlayersHand[$count][1] = $iCard[$X+1]
    $count += 1
    ConsoleWrite($count & ' hand = ' & $aPlayersHand[$count][0] & '  ' & $aPlayersHand[$count][1] & @CRLF)
    ConsoleWrite($count & '           hand = ' & $iCard[$X] & '  ' & $iCard[$X+1] & @CRLF)
Next

the $iCard[$X] and $iCard[$X+1] has data but not $aPlayersHand[$count][0] or $aPlayersHand[$count][1]

Its because you are referring to elements which do not exist. Move both ConsoleWrite calls above the $count increment.

Share this post


Link to post
Share on other sites

Dim $aPlayersHand[7][2]
Dim $iCard[14]
$COUNT = 0
For $I = 0 To 6
    For $J = 0 To 1
        $aPlayersHand[$I][$J] = $iCard[$COUNT]
        $COUNT += 1
    Next
Next
This gave the right values - yea! And NO errors - Thanks

All by me:

"Sometimes you have to go back to where you started, to get to where you want to go." 

"Everybody catches up with everyone, eventually" 

"As you teach others, you are really teaching yourself."

From my dad

"Do not worry about yesterday, as the only thing that you can control is tomorrow."

 

WindowsError.gif

WIKI | Tabs; | Arrays; | Strings | Wiki Arrays | How to ask a Question | Forum Search | FAQ | Tutorials | Original FAQ | ONLINE HELP | UDF's Wiki | AutoIt PDF

AutoIt Snippets | Multple Guis | Interrupting a running function | Another Send

StringRegExp | StringRegExp Help | RegEXTester | REG TUTOR | Reg TUTOT 2

AutoItSetOption | Macros | AutoIt Snippets | Wrapper | Autoit  Docs

SCITE | SciteJump | BB | MyTopics | Programming | UDFs | AutoIt 123 | UDFs Form | UDF

Learning to script | Tutorials | Documentation | IE.AU3 | Games? | FreeSoftware | Path_Online | Core Language

Programming Tips

Excel Changes

ControlHover.UDF

GDI_Plus

Draw_On_Screen

GDI Basics

GDI_More_Basics

GDI Rotate

GDI Graph

GDI  CheckExistingItems

GDI Trajectory

Replace $ghGDIPDll with $__g_hGDIPDll

DLL 101?

Array via Object

GDI Swimlane

GDI Plus French 101 Site

GDI Examples UEZ

GDI Basic Clock

GDI Detection

Ternary operator

Share this post


Link to post
Share on other sites

Its because you are referring to elements which do not exist. Move both ConsoleWrite calls above the $count increment.

Stupid me, that worked, sorry about the confusion.

All by me:

"Sometimes you have to go back to where you started, to get to where you want to go." 

"Everybody catches up with everyone, eventually" 

"As you teach others, you are really teaching yourself."

From my dad

"Do not worry about yesterday, as the only thing that you can control is tomorrow."

 

WindowsError.gif

WIKI | Tabs; | Arrays; | Strings | Wiki Arrays | How to ask a Question | Forum Search | FAQ | Tutorials | Original FAQ | ONLINE HELP | UDF's Wiki | AutoIt PDF

AutoIt Snippets | Multple Guis | Interrupting a running function | Another Send

StringRegExp | StringRegExp Help | RegEXTester | REG TUTOR | Reg TUTOT 2

AutoItSetOption | Macros | AutoIt Snippets | Wrapper | Autoit  Docs

SCITE | SciteJump | BB | MyTopics | Programming | UDFs | AutoIt 123 | UDFs Form | UDF

Learning to script | Tutorials | Documentation | IE.AU3 | Games? | FreeSoftware | Path_Online | Core Language

Programming Tips

Excel Changes

ControlHover.UDF

GDI_Plus

Draw_On_Screen

GDI Basics

GDI_More_Basics

GDI Rotate

GDI Graph

GDI  CheckExistingItems

GDI Trajectory

Replace $ghGDIPDll with $__g_hGDIPDll

DLL 101?

Array via Object

GDI Swimlane

GDI Plus French 101 Site

GDI Examples UEZ

GDI Basic Clock

GDI Detection

Ternary operator

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