Jump to content

Casting arrays


 Share

Recommended Posts

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
Link to comment
Share on other sites

A function that 'can' return an array does not always do so.

if isarray($aRet)= 1 then
    consolewrite("$aRef is array")
else
    consolewrite("$aRef is not array, suspect no items found")
endif
Edited by Xandy
Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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

My code:

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.

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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
Link to comment
Share on other sites

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.

Edited by Xandy
Link to comment
Share on other sites

What does

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

My code:

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.

Link to comment
Share on other sites

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

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

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.)

Link to comment
Share on other sites

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:

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.

Link to comment
Share on other sites

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
Link to comment
Share on other sites

  • Moderators

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:

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

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

clark,

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

Link to comment
Share on other sites

  • Moderators

Clark,

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:

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

 

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...