Sign in to follow this  
Followers 0
MasonMill

array index count

4 posts in this topic

hey guys,

I looked through the help file functions to no avail. Is there a way to grab the array index instead of its value?

 

Say like

$somearray[0][1]=500

$somearray[0][2]=501

$somearray[0][3]=502

$somearray[1][1]=503

$somearray[1][2]=504

$somearray[1][3]=505

 

I want to use the first array index "$somearray[0][2]" as its index and not its value, so in this case 0. Next I would use "$somearray[1][2]" as 1.  Is there a way to do this? I just dont want to create another set of variables to do this.

Thnaks in advance,

Mason

 

Share this post


Link to post
Share on other sites



#3 ·  Posted (edited)

Use Enums...or I've misread what you want:

Global Enum $iArray1d_Jeff, $iArray1d_Lilly, $iArray1d_UBound
Global Enum $iArray2d_Age, $iArray2d_Sex, $iArray2d_UBound
Global $aUsers[$iArray1d_UBound][$iArray2d_UBound]
$aUsers[$iArray1d_Jeff][$iArray2d_Age]=20
$aUsers[$iArray1d_Jeff][$iArray2d_Sex]="M"
$aUsers[$iArray1d_Lilly][$iArray2d_Age]=25
$aUsers[$iArray1d_Lilly][$iArray2d_Sex]="F"

ConsoleWrite("Jeff is Aged=[" & $aUsers[$iArray1d_Jeff][$iArray2d_Age] & "]." & @CRLF)
Edited by jdelaney

IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.

Share this post


Link to post
Share on other sites

Nice jdelaney. Finally someone gets it!


_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_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: 04/09/2015

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

  • Similar Content

    • FrancescoDiMuro
      By FrancescoDiMuro
      Good evening
      I was looking around the forum if I could find a function that allows to convert a string into a 2 dimensional array...
      The first column of the array is always the same, but the rows could change...
      I have a pattern like:

      Column A|Column B
      Static Text 1|Data 1
      Static Text 2|Data 2
      Static Text 3|Data 3
      Static Text 4|Data 4

      Where, Static Text (1...4) will be always the same, and I don't want to change them... But, Data 1...4 are dynamic fields... So, I could have the pattern above AND I coould have the pattern I'm going to show you right below

      Column A|Column B
      Static Text 1|Data 1
      Static Text 2|Data 2
      Static Text 3|Data 3
      Static Text 4|Data 4
      Static Text 1|Data 5
      Static Text 2|Data 6
      Static Text 3|Data 7
      Static Text 4|Data 8

      How can I do in this case?

      Thanks for everyone's help


       
    • ur
      By ur
      I have a string with comma seperated as below.
      Name="Test-win10x64,Test-win10x65,Test-win10x67"
      $machine_names = StringSplit($tempINIValue, ',', $STR_ENTIRESPLIT) with the above line i can get a single dimension array.
      But I want a tabular format array like 4X4 where I want to add the 4 single dimension arrays as different columns in them.
       
      Is there any option to do the same.
    • 232showtime
      By 232showtime
      im getting strange output in array display,$split_[1] is not properly aligned to other arrays and why guictrlsetdata is not writting any data if i put comma(,) at the end of the text in $Input1???
       
      #include <ButtonConstants.au3> #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <Array.au3> #Region ### START Koda GUI section ### Form=C:\Users\user\Desktop\Script\StringSplit.kxf $Form1 = GUICreate("Form1", 623, 449, 192, 114) $Input1 = GUICtrlCreateInput("50UGITQ421X, 50UGITQ422X, 50UGITQ423X, 50UGITQ427X, 50UGITQ431X, 50UGITQ435X, 50UGITQ436X, 50UGITQ437X, 50UGITQ441X, 50UGITQ445X, 50UGITQ449X, 50UGITQ453X, 50UGITQ454X, 50UGITQ455X, 50UGITQ459X", 24, 16, 553, 21) $Split = GUICtrlCreateButton("Split", 24, 48, 75, 25) $List1 = GUICtrlCreateList("", 24, 96, 553, 97) GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $Split $read = GUICtrlRead($Input1) $split_ = StringSplit($read, ",") $Max = UBound($split_, 1) For $i = 1 To UBound($split_) - 1 ConsoleWrite($split_[$i] & @CRLF) ;~ ControlSetText($Form1, "", $List1, $split_[$i]) GUICtrlSetData($List1, $split_[$i]) ;~ GUICtrlSetData($List1, $split_[$i]) ;~ GUICtrlSetData($List1, $i) Next _ArrayDisplay($split_) EndSwitch WEnd  
    • hcI
      By hcI
      Hey !
      I was looking for an array display to see the result of StringSplit but when i called the <Array.au3>, an error is showing up when i try to launch the script.
      I took a screenshoot of the windows dialog box error : imp.bmp
      And when I look into the Array.au3 there is no error :
      Why is it doing this ?
    • spudw2k
      By spudw2k
      I was reading a recent post about converting a 2D array into a 1D array.  The OP, from my understanding, more-or-less wanted to extract a single column of data and format it in a 1D array.  The solutions were proper and efficient compared to what I wanted to share, but I figured I'd share as it's a good lesson and a neat, purely mathematical approach to mapping an index to a 2D array.  As-is, this only works for 2D arrays.  
      By knowing how big a 2D array is, an index can be calculated for each indices/subscript.  The functions below define a random sized 2D array, and calculate an index that matches the indices on the 2D array.
      #include "Array.au3" $iRow = Random(2,10,1) $iCol = Random(2,10,1) $iRandomIndex = Random(0,($iRow*$iCol)-1,1) $sIndicies = _IndexTo2DIndicies($iRandomIndex, $iRow, $iCol) _2DArrayTo1DIndexes($iRow, $iCol, $iRandomIndex & " = $aArr" & $sIndicies) Func _2DArrayTo1DIndexes($iRow = 1, $iCol = 1, $sMsg = Default) $iRow = Int($iRow) $iCOl = Int($iCol) Local $aData[$iRow][$iCol] For $iY = 0 to $iRow - 1 For $iX = 0 to $iCol - 1 Local $iIndex ;Index = ($iColMax * $iY) + $iX $aData[$iY][$iX] = ($iCol * $iY) + $iX Next Next If $sMsg = Default Then $sMsg = "1D Indexes of 2D Array Indicies" _ArrayDisplay($aData,$sMsg) EndFunc Func _IndexTo2DIndicies($iIndex = 0, $iRow = 0, $iCol = 0) $iIndex = Int($iIndex) $iRow = Int($iRow) $iCol = Int($iCol) If $iIndex = 0 Then Return "[0][0]" If $iIndex >= $iRow * $iCol Then Return SetError(1,0,0) Local $iX = Mod($iIndex, $iCol) ;Local $iY = ($iIndex-$iX) / $iCol Local $iY = Int($iIndex / $iCol) ;Thanks Chimp Return "[" & $iY & "][" & $iX & "]" EndFunc I used this type of approach before with a pixel array.  I had a 1D array for storing individual pixel information, then mapped the pixels to an X|Y grid (2D array or XY coords).

      Now if the purpose is just to flatten an array, the most efficient way I am aware of would be to create a new 1D array the size of the total number of indices in the 2D array (RowMax * ColMax), and loop through the array.  I suppose these methods (above) would be particularly useful if you need to randomly or programmatically access indices in a non-linear fashion.

      Anyways, just wanted to share a fun exercise with arrays.