Jump to content

Recommended Posts

Posted

Hi there

This has been bugging me for sometime now, but usually I just work around it.

I think now is a good time for me to get me head around what is going on.

In the following code, the _ArrayDisplay function works, indicating that $aRet is an array. (It definitely is an array as that is what the function returns.)

Yet, when I try to use $aRet[0][0] so that I can see it's value, I get the "Subscript used with non-Array variable." error. Why is this when $aRet is definitely an array?

$aRet = _GUIListViewEx_Editonclick($iEditMode) ; Allow keys to move edit location
_ArrayDisplay($aRet)
if $aRet[0][0]=1 then
$lvitem=_GUIListViewEx_ReturnArray(1)
_Display_Icons()
EndIf
Posted

Hmmm, but wouldn't _ArrayDisplay bork if that was the case?

But let's assume for a second that it is not returning an array (even though _DisplayArray is showing the contents I need at element 0,0 and at 1,0), is there a way I can retrieve the elements that have been returned somehow, so I can use them?

Posted

It seems that $aRet isn't a 2D array it may be 1D. Have you tried $aRet[0] = 1 Then?

My code:

  Reveal hidden contents
PredictText: Predict Text of an Edit Control Like Scite. Remote Gmail: Execute your Scripts through Gmail. StringRegExp:Share and learn RegExp.

Run As System: A command line wrapper around PSEXEC.exe to execute your apps scripts as System (LSA). Database: An easier approach for _SQ_LITE beginners.

MathsEx: A UDF for Fractions and LCM, GCF/HCF. FloatingText: An UDF for make your text floating. Clipboard Extendor: A clipboard monitoring tool. 

Custom ScrollBar: Scroll Bar made with GDI+, user can use bitmaps instead. RestrictEdit_SRE: Restrict text in an Edit Control through a Regular Expression.

Posted

  On 4/23/2013 at 3:54 AM, 'PhoenixXL said:

It seems that $aRet isn't a 2D array it may be 1D. Have you tried $aRet[0] = 1 Then?

Nope, that gives the same result.

Here is the return variable definition in the udf:

Local $aEdited[1][3] = [[0]]

Could it be something to do with my autoit installation, as I have had similar problems with array variables before?

Posted (edited)

  Clark said:

Could it be something to do with my autoit installation, as I have had similar problems with array variables before?

I don't know.

Have you tried re-installing AutoIt and 'AutoIt Script Editor'?

http://www.autoitscript.com/site/autoit/downloads/

Edited by Xandy
Posted

What does

UBound($aRet, 0)
Return in your case ?

My code:

  Reveal hidden contents
PredictText: Predict Text of an Edit Control Like Scite. Remote Gmail: Execute your Scripts through Gmail. StringRegExp:Share and learn RegExp.

Run As System: A command line wrapper around PSEXEC.exe to execute your apps scripts as System (LSA). Database: An easier approach for _SQ_LITE beginners.

MathsEx: A UDF for Fractions and LCM, GCF/HCF. FloatingText: An UDF for make your text floating. Clipboard Extendor: A clipboard monitoring tool. 

Custom ScrollBar: Scroll Bar made with GDI+, user can use bitmaps instead. RestrictEdit_SRE: Restrict text in an Edit Control through a Regular Expression.

Posted

UBound is preferred over IsArray. IsArray is useful for those starting out with arrays and have no clue what UBound is for.

UDF List:

  Reveal hidden contents

Updated: 22/04/2018

Posted

  On 4/23/2013 at 6:40 AM, 'Xandy said:

I'll setup _GUIListViewEx_Editonclick(), that's Melba's function from here ?

Run your example, and tell you how it works on my machine?

edit: please show me how you declare and define $iEditMode.

Thanks Xandy,

Global $lvitem,$iLV_List,$listbox,$hImage,$iEditMode = 0 is how it is declared and defined.

Phoenix, ubount($aRet,0) returns 0 in all cases, i.e. when editing and when not editing.

I can post my code here tomorrow if it helps? (Obviously I will cut it down to the pertinent parts.)

Posted
  Quote

Phoenix, ubount($aRet,0) returns 0 in all cases, i.e. when editing and when not editing.

It means the return isn't an array, check out the @error macro after calling the respective function to find out where the error occured, if still not sure you should ask to the author of the function through the Topic where the Function is present/uploaded.

My code:

  Reveal hidden contents
PredictText: Predict Text of an Edit Control Like Scite. Remote Gmail: Execute your Scripts through Gmail. StringRegExp:Share and learn RegExp.

Run As System: A command line wrapper around PSEXEC.exe to execute your apps scripts as System (LSA). Database: An easier approach for _SQ_LITE beginners.

MathsEx: A UDF for Fractions and LCM, GCF/HCF. FloatingText: An UDF for make your text floating. Clipboard Extendor: A clipboard monitoring tool. 

Custom ScrollBar: Scroll Bar made with GDI+, user can use bitmaps instead. RestrictEdit_SRE: Restrict text in an Edit Control through a Regular Expression.

Posted (edited)

Have you loaded example2 from Melba's UDF?

You should have a look if you haven't

;Do you:
;create a gui
$hGUI = GUICreate("LVEx Example 2", 640, 430)

;create a listbox
$cListView_Left = GUICtrlCreateListView("Tom", 10, 40, 250, 300, $LVS_SINGLESEL)

; Create array and fill the listview with items
Global $aLV_List_Left[$iCount_Left + 1] = [$iCount_Left]
For $i = 1 To UBound($aLV_List_Left) - 1
   $aLV_List_Left[$i] = "Tom " & $i - 1
   GUICtrlCreateListViewItem($aLV_List_Left[$i], $cListView_Left)
Next

; Initiate ListViewEx with the listbox control you just made
$iLV_Left_Index = _GUIListViewEx_Init($cListView_Left, $aLV_List_Left, 1, 0x0000FF, False, 2)

;have the _GUIListViewEx_Editonclick($iEditMode) in a loop?

I don't know this UDF but that's what I would check at this point.

Edited by Xandy
  • Moderators
Posted (edited)

Clark,

I can explain what is happening. The function does indeed return an array - but only if an item in the ListView was doubleclicked. If nothing was double-clicked (i.e on most passes through the idle loop) then the function does not return an array but just an empty string. As I was just using _ArrayDisplay to display the returned array (and which just passes over a non-array parameter) I did not realise that this would cause a problem. There are several AutoIt functions and UDFs that do not always return arrays (e.g. IniReadSection, _FileListToArray) and quite frankly I did not expect the user to try and access the return without checking that there was actually an array present. It seems I was wrong. :(

I will amend the function header to make clear that an array is only returned from an edit process launched by a double-click and that the user needs to check for the existence of an array before trying to access it. :)

M23

Edit:

; Return values .: If no double-click: Empty string
;                  After double-click: 2D array of zero-based [row][column] items edited - total edits in [0][0]
;                                      Failure: Sets @error as follows:
;                                          1 - ListView not editable
;                                          2 - Empty ListView
;                                          3 - Column not editable
[...]
;                  The function only returns an array after an edit process launched by a double-click.  If no
;                  double-click has occurred, the function returns an empty string.  The user should check that a 
;                  valid array is present before attempting to access it.
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:

  Reveal hidden contents

 

Posted

Well thanks all, problem solved!

(I feel guilty about causing all this fuss, but all is good in the end. I don't think I deserved to be called a "user" though. :) )

Thanks again all, especially Melba23 for making such a useful udf.

Posted

clark,

  Quote

Hmmm, but wouldn't _ArrayDisplay bork if that was the case?

It is but you are not checking the return

#include <array.au3>
local $scalar_var
_arraydisplay($scalar_var)
switch @error
 case 1
  ConsoleWrite('Not an array' & @LF)
 case 2
  ConsoleWrite('more than 2D array' & @LF)
endswitch

kylomas

Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

  • Moderators
Posted

Clark,

  Quote

I don't think I deserved to be called a "user" though

Purely generic usage of the term on my part - nothing personal. :whistle:

Glad you like the UDF. :)

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:

  Reveal hidden contents

 

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
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...