Jump to content

Array access on expression & first element


DXRW4E
 Share

Recommended Posts

can be enabled (in Array access on expression) to readaccess the first itemelement directly (without specify it), example

Local $aTest1[4] = [1,2,3,4], $aTest2[4] = ["One","Two","Three","Four"], $aTest3[4][4] = [[0,1,2,3],[4,5,6,7]], $aTest4
If ($aTest1) = 1 Then
    ;ect ect ect
EndIf

If ($aTest2) = "One" Then
    ;ect ect ect
EndIf

If ($aTest3) = 0 Then
    ;ect ect ect
EndIf

If ($aTest4) = "XXXX" Then
    ;ect ect ect
EndIf

would be useful during DllCall or other Function that return array variable, so do not need to check first if the $aTest is an valid array variable ect ect

Ciao.

Edited by DXRW4E

apps-odrive.pngdrive_app_badge.png box-logo.png new_logo.png MEGA_Logo.png

Link to comment
Share on other sites

My reply from trac. #2604

  • Resolution set to Rejected
  • Status changed from new to closed

Not a good idea. It would have to be a special case, that only applies when the array is used with a comparison operator as there would be other cases where it wouldn't work.

We'd probably start seeing code like:

If $a = 0 Then
    $a = 4
EndIf

A confusing feature, especially in a large code base, even with systems hungarian. For pretty much no saving either. Sure for arrays that have the count in the first index it might be nice.

I've rejected the request. PM me on the forums if you want to discuss it further, if another MVP or dev would like this feature then they can re-open the ticket.

Link to comment
Share on other sites

My reply from trac. #2604

  • Resolution set to Rejected
  • Status changed from new to closed
Not a good idea

i think you made your decision a little early, you are wrong because the feature already exists ??, you know that right??

AutoIt v3.3.10.0 (23rd December, 2013) (Release)

Added: Array access on expression: StringSplit("a,b", ",")[1]

Retun (StringSplit("a,b", ","))[0]
;or
Retun (StringSplit("a,b", ",")) ;Improvement (Feature) Request
however i think you have not understood very well the (Feature) Request, everything refers to the Array access on expression (Feature that already exists, i asked only an improvement), there is nothing to be confused, Array access on expression never modify the array variabledata, indeed is useful during Return or Comparison or Assignment or anything like that

there are a lot of differences, StringSplit always return arrays so never happens error, but it is very useful in cases happens error, to give an example

;ERROR, if error happens during Dllcall, name.dll not found or other
Return (DllCall("name.dll", "int", "FuncName", "str", "", "int", 111))[0]

;is always OK, even if error happens during Dllcall, name.dll not found or other
Return (DllCall("name.dll", "int", "FuncName", "str", "", "int", 111)) ;Improvement (Feature) Request
is the same thing also during the Comparison or Assignment or anything like that, so never go in error, even if variable is arrays or not, here is to avoid these errors

Local $aTest[4] = ["One","Two","Three","Four"], $sTest, $aTest2
$sTest = ($aTest) ;Improvement (Feature) Request
ConsoleWrite("$sTest - " & $sTest & @LF)
$sTest = ($aTest)[0]
ConsoleWrite("$sTest - " & $sTest & @LF)
$aTest2 = "Two"
$sTest = ($aTest2) ;Improvement (Feature) Request
ConsoleWrite("$sTest - " & $sTest & @LF)
$sTest = ($aTest2)[0]
ConsoleWrite("$sTest - " & $sTest & @LF)

;~ >Running AU3Check (3.3.11.1)  from:C:\Program Files (x86)\AutoIt3\Beta
;~ +>02:50:57 AU3Check ended.rc:0
;~ >Running:(3.3.11.1):C:\Program Files (x86)\AutoIt3\Beta\autoit3.exe "C:\Users\DXRW4E\Desktop\New AutoIt v3 Script.au3"    
;~ --> Press Ctrl+Alt+F5 to Restart or Ctrl+Break to Stop
;~ $sTest - 
;~ $sTest - One
;~ $sTest - Two
;~ "C:\Users\DXRW4E\Desktop\New AutoIt v3 Script.au3" (10) : ==> Subscript used on non-accessible variable.:
;~ $sTest = ($aTest2)[0]
;~ $sTest = ($aTest2)^ ERROR
;~ ->02:50:57 AutoIt3.exe ended.rc:1
;~ >Exit code: 1    Time: 0.436
everything will be as always nothing will change, so it does not create confusion, but to the contrary, it helps a lot in all cases

Ciao.

Edited by DXRW4E

apps-odrive.pngdrive_app_badge.png box-logo.png new_logo.png MEGA_Logo.png

Link to comment
Share on other sites

  • Moderators

DXRW4E,

I see absolutely no benefit in this feature request - to my eyes all it will add is confusion between:

$sTest = ($aTest) ;Improvement (Feature) Request to return the [0] element

; and

$sTest = $aTest ; Existing syntax for copying of an array
And Mat's snippet from Trac is another example where confusion is likely to occur. :wacko:

Please remember that AutoIt is designed for all levels of coder. Many feature requests are from experienced coders and more often than not are aimed at edge cases. The AutoIt team have to think of the language as a whole and some of these suggestions are deemed likely to be more trouble that they are worth. Do not take this personally - if there were no suggestions for improvements then we would all suffer - but please bear in mind that although you can make suggestions there is nothing that says they have to be accepted. :)

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

Hi Melba23, is all Ok, the long post above is not out of anger or anything like that, indeed (how to say) even if i do not liked the answer, i found the post of Mat kindlyfriendly (although as i said i think it was wrong), it was just to explain why i think so nothing else

 

I see absolutely no benefit in this feature request - to my eyes all it will add is confusion between:

$sTest = ($aTest) ;Improvement (Feature) Request to return the [0] element

; and

$sTest = $aTest ; Existing syntax for copying of an array

I think in my post above there are examples of why is helpful, as i said this does not change anything in autoit script, so no one confuses them, those who want to can use the feature, who does not want does not use it is everything same, will be just the same as the use of the Array access on expression, as said the feature already exists (for this in the beginning is wrote "can be enabled" and not "can be added")

 

Do not take this personally

do not worry never took it personally, in general i believe one that takes its decisions, has its reasons right or wrong they are, so in the end is everything is ok for me

however to make (all) it short, i really do not see where is the confusion here, for now in AutoIt ($aArray) is equal to '""' (None), only asked to pass ($aArray) equal the first element nothing else what changes or what confuses this ??

Ciao.

Edited by DXRW4E

apps-odrive.pngdrive_app_badge.png box-logo.png new_logo.png MEGA_Logo.png

Link to comment
Share on other sites

How are you supposed to distinguish between checking the array and checking the first element? I'm not seeing any new syntax there.

just as you do right now, or how you always fate, nothing will change them

Ciao.

Edited by DXRW4E

apps-odrive.pngdrive_app_badge.png box-logo.png new_logo.png MEGA_Logo.png

Link to comment
Share on other sites

I'm afraid that this means absolutely nothing to me. Could you rephrase it?

as you've always done, does not change anything there

 

Local $aArray[2] = [1, "Test"], $aTest, $sTest, $iTest

$aTest = $aArray
$sTest = $aArray[1]
$iTest = ($aArray)[0]
$iTest = ($aArray) ; ""

$iTest = ($aArray) ; Improvement (Feature) Request to return the [0] element

so what need to know or to add here

Ciao.

Edited by DXRW4E

apps-odrive.pngdrive_app_badge.png box-logo.png new_logo.png MEGA_Logo.png

Link to comment
Share on other sites

Well if it now evaluates to the first element then it will always return false.

No it wouldn't.

DXRW4E, the idea not good because you are somehow forgetting that first element of array can be some other array. Try your idea with that in mind now.

♡♡♡

.

eMyvnE

Link to comment
Share on other sites

Well if it now evaluates to the first element then it will always return false.

I think nothing more and nothing less, of what happens when it was added Array access on expressionn in AutoIt v3.3.10.0

 

DXRW4E, the idea not good because you are somehow forgetting that first element of array can be some other array. Try your idea with that in mind now.

right observation, in that case return '""' (None), as always (as is already do now), where the problem ?? (as i said nothing is going to change them), however as always is the duty of user to be certain at what he does, there does not exist any thing without the risk ehhh

Ciao.

Edited by DXRW4E

apps-odrive.pngdrive_app_badge.png box-logo.png new_logo.png MEGA_Logo.png

Link to comment
Share on other sites

right observation, in that case the return '""' (None), as always (as is already do now), where the problem ?? (as i said nothing is going to change them), however as always is the duty of user to be certain at what he does, there does not exist any thing without the risk

Ciao.

See this:

Local $aOtherArray = [555, 444, 333]
Local $aArray = [$aOtherArray, 2, 3]

$vVal = ($aArray)[0]

ConsoleWrite($vVal & @CRLF)

That code prints nothing (array is "nonprintable"). That's what is should print.

With your idea it would print 555. Do you see how this breaks scripts?

Edited by trancexx

♡♡♡

.

eMyvnE

Link to comment
Share on other sites

Hi trancexx, no it will have to Return None ???

$aArray[0] is array of arry, so

Local $aOtherArray = [555, 444, 333]
Local $aArray = [$aOtherArray, 2, 3]

;$aArray[0] is Array of Array
; ($aArray)[0] ; is Array
; ($aArray[0])[0] is equa 555
; ($aArray[0]) ; Improvement (Feature) Request, will have to Return 555

;$vVal = ($aArray)[0]    ;Array
;ConsoleWrite($vVal & @CRLF)

$vVal = ($aArray[0]) ; Improvement (Feature) Request to return the [0] element, will have to Return 555
ConsoleWrite($vVal & @CRLF)

$vVal = ($aArray) ; Improvement (Feature) Request to return the [0] element, will have to Return '""' None or Array
; since the $aArray[0] is arrays, as already mentioned as is already do
ConsoleWrite($vVal & @CRLF)

Ciao.

Edited by DXRW4E

apps-odrive.pngdrive_app_badge.png box-logo.png new_logo.png MEGA_Logo.png

Link to comment
Share on other sites

Hi trancexx, is creating confusion for nothing, I mean is simple if the return is Array or other as always return dataNonearray (is not important), as I said nothing will change them (nothing at all), just as it does with the Array access on expression anything else, just to change the return None of ($aArray) with ($aArray) return firs element, so the ($aArray) will always be equal to the ($aArray)[0], but for the reasons said in the post before ($aArray) is more help in many situations, since return will always be OK  (valid, no AutoIt Error), no need to check first if the $aArray is a valid array variable, exampe

;is OK, but if error happens during Dllcall ehhh, Autoit Error (blocks\terminates execution) of the exe\script 
If (DllCall("Kernel32.dll", "long", "GetLastError"))[0] Then
    ;ect ect
EndIf
;;or
Return SetError((DllCall("Kernel32.dll", "long", "GetLastError"))[0], 0, $data)

;is always OK, even if error happens during Dllcall, Kernel32.dll not found or other
If (DllCall("Kernel32.dll", "long", "GetLastError")) Then;Improvement (Feature) Reques
    ;ect ect
EndIf
;;or
Return SetError((DllCall("Kernel32.dll", "long", "GetLastError")), 0, $data)

in poor words ($aArray) for now has no function in Autoit (always return None, if you do not use the Array access on expression),  everything so simple nothing will change them, only add that the ($aArray) from None to Return firs element

Ciao.

Edited by DXRW4E

apps-odrive.pngdrive_app_badge.png box-logo.png new_logo.png MEGA_Logo.png

Link to comment
Share on other sites

There seems to be a language issue preventing you from understanding what we are saying.

in poor words ($aArray) for now has no function in Autoit (always return None, if you do not use the Array access on expression), everything so simple nothing will change them, only add that the ($aArray) from None to Return firs element

you see any problem here?? Edited by DXRW4E

apps-odrive.pngdrive_app_badge.png box-logo.png new_logo.png MEGA_Logo.png

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