Quantcast
Channel: AutoIt v3 - General Help and Support
Viewing all articles
Browse latest Browse all 12506

insert in 2 demensional array

$
0
0

Hi,

 

i am using a two dimensional array like this:

 

Dim $formfields[3][2] = [["element1", "data1"],["element2", "data2"],["elemnt0","data0"]]

 

there can be x elements.

 

My problem is that i need to have a certain element at the first position (the order of the other elements does not matter, only on certain element hast to be at position 1).

 

Dim $formfields[3][2] = [["element0", "data0"],["element1", "data1"],["elemnt2","data2"]]

 

I wanted to check if a certain element exist in formfields and if it exists, i remove it and re insert it at position 1. If it does not exist, i just want to add it at position 1.

 

I tried several things, but i could not get this done correctly, due to problems with the array dimensions after removing/adding...

 

Can anyone show me how to do it right?

 

thanks in adnvance,

 

Edit:

 

here is what already works:

AutoIt Code         
Func _AddOrUpdateFieldIn2DArray($array, $fieldname, $data = "")     $iIndex = _ArraySearch($array, $fieldname, 0, 0, 1, 2, 1, 0)     If $iIndex <> -1 Then;the field exists         If $array[$iIndex][1] = $data Then                                ;already up to date         Else             ;update                      $array[$iIndex][1] = $data         EndIf     Else             ;add             ReDim $array[UBound($array) + 1][2]         $array[UBound($array) - 1][0] = $fieldname         $array[UBound($array) - 1][1] = $data     EndIf     Return $array EndFunc  

and would like to have something like this also:

AutoIt Code         
Func _AddTobeginningOf2DArray($array, $fieldname, $data = "") ;adds $fieldname to the beginning of the array, removes $filedname from other positions if it already exists     Return $array EndFunc  

Viewing all articles
Browse latest Browse all 12506

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>