Jump to content

Vector has to be Local on assignment line else syntax error


Recommended Posts

This works in a long script:

Local $ar,$vec
    For $fnam in $udfFnamsVec
        $vec = GetFnamsInaMgmt_Hhc('udf',$gudfLvlFnamAr,$fnam)
        For $i = 0 to UBound($vec)-1
            Local $tvec = [$vec[$i],$fnam]
            AppendRowToArray($ar,$tvec)
        Next
    Next

but this gives a syntax error:

Local $ar,$vec,$tvec
    For $fnam in $udfFnamsVec
        $vec = GetFnamsInaMgmt_Hhc('udf',$gudfLvlFnamAr,$fnam)
        For $i = 0 to UBound($vec)-1
            $tvec = [$vec[$i],$fnam]
            AppendRowToArray($ar,$tvec)
        Next
    Next

Why?

Edited by c.haslam
Spoiler

CDebug Dumps values of variables including arrays and DLL structs, to a GUI, to the Console, and to the Clipboard

 

Link to comment
Share on other sites

  • Developers

You could have summarized it that this works:

Local  $tvec = [$vec[$i],$fnam]

And this gives an Error:

$tvec = [$vec[$i],$fnam]

You are trying to define an Array and need to use Dim/Global/Local

Jos

 

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

OK. But consider $vec:

  • On the first line of my code, it is declared (as a scalar?)
  • On the third line, AutoIt changes it to being a vector, because the function returns a vector.

Am I correct?

Please also consider $ar. A 2D array had been assigned to it in a previous line of the code. Despite declaring it (without a value) on line 1 of the code above, it picked up the previous value, assigned earlier in the function. So re-declaring a variable as Local with no initial value does nothing.

I solved the problem by changing the first line to

Local $ar='',$vec

Am I correct?

I looked in the Help but did not find anything  there to help.

BTW I see that Language Reference > Variables still shows Map, despite Jon having withdrawn this feature. Perhaps it should either be removed or mentioned as a future feature.

Further, as I read this help topic, I see Using empty [ ] declares a Map but an example of an array is Local $vVar[] = [1, 2, 3]. Is Using empty [] without an initializer declares a Map intended?

I am using v. 3.3.14.0

Edited by c.haslam
Spoiler

CDebug Dumps values of variables including arrays and DLL structs, to a GUI, to the Console, and to the Clipboard

 

Link to comment
Share on other sites

  • Moderators

c.haslam,

Every time you declare an array (whether empty or filled) you must use a scoping keyword - that is probably the only reason that we keep Dim, so that you can re-declare an array in a UDF without worrying whether it was Local or Global in scope in the calling script.

The Map stuff on that page should have been removed - but as it will still be in the next Beta I am not going to lose any sleep over its inclusion.

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