Jump to content
Sign in to follow this  
agreiner

Calling _ArraySearch; with 2D array; getting error.

Recommended Posts

agreiner

I have an array ($variables), which has 2 dimensions (0 = name, 1 = value). I am trying to search the array to return the value for a given name. I know that I missing something very simple, yet I have no idea what it is.

_ArraySearch($variables,$name,0,0,0,0,0,0)

When I try to run this, I get:

ERROR: _ArraySearch() previously called with expression on Const ByRef param(s).

Can someone point me in the right direction?

Thanks

Share this post


Link to post
Share on other sites
Melba23

agreiner,

Welcome to the AutoIt forum. :graduated:

Please post all of your script - there is something wrong with the way you have declared $variables and/or $name by the look of it. ;)

M23

Edit: And it looks as is you have not set the $iSubItem parameter correctly if you are looking for the second column. :)

P.S. When you post code please use Code tags. Put [autoit] before and [/autoit] after your posted code.

Edited by Melba23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites
agreiner

Unfortunately, I am not allowed to post all of my code (non-disclose agreement); however, I will work on extracting the important bits and see if I can reproduce the issue (that way I can post it, without violating my non-disclose).

Share this post


Link to post
Share on other sites
Melba23

agreiner,

Fine - but we need some working(ish) code which demonstrates the same problem. :graduated:

M23


Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites
agreiner

Melba,

Thanks for the help. You resolved my issue with:

there is something wrong with the way you have declared $variables and/or $name by the look of it. :graduated:

While attempting to reproduce this issue, I realized that I had declared $variables as Global, then tried to declare it again in the Local scope, later in the script. This code works:

#include <Array.au3>
;Create the XML Object
$o = ObjCreate("Msxml2.DOMDocument")
$o.load("C:\Documents and Settings\agreiner\Desktop\forumexample.xml")
$o.setProperty("SelectionLanguage", "XPath")
$oVariables = $o.selectNodes("//test/variables/variable")
;Count the variables
$varcount = 0
For $oVariable In $oVariables
$varcount+=1
Next
;Declare variables array
Global $variables[$varcount][2]
;populate the variables array
$i = 0
For $oVariable In $oVariables
$variables[$i][0] = _NodeGetValue($oVariable.attributes.getNamedItem("name"))
$variables[$i][1] = _NodeGetValue($oVariable.attributes.getNamedItem("value"))
$i+=1
Next
;sort the array alphabetically by variable name (not needed)
;_ArraySort($variables,0,0,0,0)
MsgBox(0,"Var1",VariableFindValue("Var1"))
Func VariableFindValue($name)
$check = _ArraySearch($variables,$name,0,0,0,0,1,0)
If $check < 0 Then
  Return @error
EndIf
Return $variables[$check][1]
EndFunc
Func _NodeGetValue(Const $oNode, $vDefault = "")
    If Not IsObj($oNode) Then Return SetError(1, 0, $vDefault)
    Return $oNode.value
EndFunc

Edit: I guess an xml snippet may be useful as well:

<?xml version='1.0' encoding='UTF-8'?>
<test>
<variables>
  <variable name="var3" value="0"/>
  <variable name="var2" value="2"/>
  <variable name="var1" value="8"/>
  <variable name="var5" value="5"/>
  <variable name="var4" value="6"/>
</variables>
</test>
Edited by agreiner

Share this post


Link to post
Share on other sites
Melba23

agreiner,

Nice to see the remote debugging skills are still up to scratch! :graduated:

M23


Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

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  

×