Jump to content

What am i doing wrong?


Recommended Posts

#include <Array.au3>
global $arr[2][2]
$arr[0]['x'] = 11
$arr[0]['y'] = 22
$arr[1]['x'] = 33
$arr[1]['y'] = 44

displayArray($arr)

Func displayArray($array)
   For $i = 0 to UBound($array, 1) - 1
         MsgBox(0,"AutoIt",$array[$i]['x'])
         MsgBox(0,"AutoIt",$array[$i]['y'])
   Next
EndFunc

I expect 4 boxes with text 11...22...33...44

instead i get 22...22...44...44

What am i doing wrong?

Link to comment
Share on other sites

ahh

Actually nope! I won't :)

It does not say anything about associative arrays. I have naturally assumed a high level lang should be able to handle string keys and it didn't even cross my mind that "index numbers" should be taken literally :)

It does speak of multidimentional arrays but does not mention they are actually matrix and not array or arrays like the other langs. I can store matrix data only in matrix values and can't use the keys the same way. I wouldn't know that if i haven't read it in the forums here.

The "UBound" workaround of foreach is not actual replacement :)

Here is an example:

I have incoming a simple text file with unknown count of x,y coordinates which i want to load and use. For example in perl my original script from this thread would look like this:

$arr{11}=22;
$arr{33}=44;
...

foreach $key (keys %arr) {
   print "X->" . $key . " ,Y-> " . $arr{$key};
}

In PHP it would be even simpler :)

Try to write it in autoit and you'll see what i mean and why i got confused :)

And i don't even want to think how complex the definition will get if i have z coord too :)

Edited by Thimotty
Link to comment
Share on other sites

PHP has it's problems as well. Also it's an array, AutoIt has never pretended that it's anything but that.

Edited by guinness

UDF List:

 
_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_ArrayFilter/_ArrayReduce_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 22/04/2018

Link to comment
Share on other sites

.

The "UBound" workaround of foreach is not actual replacement :)

You really should read the help file, even though I know you won't.

Local $aArray = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
For $iNum In $aArray
    ConsoleWrite($iNum & @CRLF)
Next

4 posts in and you're already exhibiting the attitude of someone who won't last very long around here. I like to think people can change, but given the way you conversed with Zedna, when they provided clear help and advice, shows me your lack of respect to those who know more about the language (AutoIt) than you.

UDF List:

 
_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_ArrayFilter/_ArrayReduce_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 22/04/2018

Link to comment
Share on other sites

No, guinness, probably i won't.

I did thank Zedna properly, i think.

When i share s simple thought that something is strange for me to be send to "go RTFM" or "google it" is considered kinda rude.

When i try to explain what and why did confused me to be told that i am "exhibiting the attitude" and I "won't last very long around here" is absolutely rude.

Yes i know they are called hashes in perl and php has it's problems but they still are (or can be used as) arrays of arrays.

Please, old dog, do not assume that someone has not read the manual, especialy when same one explains what confused him in the manual :)

I am sorry if you or anyone else feel that my posts are offensive, when they are not! Your attitude (and very likely what follows) will drive me away.

Best regards and take it easy!

Link to comment
Share on other sites

Asking very basic questions can be considered rude too.

I was going to tell you about FOR IN LOOP but guinness was faster.

As he said you don't read helpfile well else you couldn't write that AutoIt can't handle this/that ... for example arrays in arrays are posiible too.

EDIT: You also posted in wrong section of this forum and you used absolutely wrong titile of topic :-(

Edited by Zedna
Link to comment
Share on other sites

Yes they are possible but you can't use them unless you get tem out of the array into another variable.

Anyway

Please accept my apologies for beeg rude and asking so basic question. Thank you again for your kind help!

Edit: Yes i apologize for that too. Asking programing question in developers chat was really rude. Please don't be too mad at me!

Edited by Thimotty
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...