Sign in to follow this  
Followers 0
Kalin

Exactly, what does -1 mean

22 posts in this topic

In au3, what does the -1 number mean.

It's a number so frequently used in autoit.

Can anyone share with me what it is, what it's used for? < purposes

Share this post


Link to post
Share on other sites



usually its used to represent a default value. inside the fuction there will be an if statement say:

If $param = -1 Then $Param = $SomeConstant

Share this post


Link to post
Share on other sites

usually its used to represent a default value. inside the fuction there will be an if statement say:

If $param = -1 Then $Param = $SomeConstant

Can you give more detail please?

Thank you for helping in all, but the value -1 isn't really explained at all in the helpfile.

So I'll need full detail please.

Share this post


Link to post
Share on other sites

It depends on the context, what -1 may mean.

As a condition parameter, it may mean the number value negative one or just a non-zero value to mean True.

As a Step parameter in a For...Next loop, it means that the loop goes in a decreasing increment of one.

As an @error or @extended value, it may mean whatever the function designer wants it to indicate.

Share this post


Link to post
Share on other sites

It depends on the context, what -1 may mean.

As a condition parameter, it may mean the number value negative one or just a non-zero value to mean True.

As a Step parameter in a For...Next loop, it means that the loop goes in a decreasing increment of one.

As an @error or @extended value, it may mean whatever the function designer wants it to indicate.

Finally! Someone gave me a answer without thinking I'm trying to be offensive, thank you good sir.

;)

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

As an example please see the help file for GUICreate. -1 means "center" if specified for the "left" or "top" parameter for this function.

-1 might mean something completely different for another function.

Edited by water

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

Ok so lets take say, GUICtrlCreateEdit

GUICtrlCreateEdit ( "text", left, top [, width [, height [, style [, exStyle]]]] )

The default style is:

BitOR($ES_WANTRETURN, $WS_VSCROLL, $WS_HSCROLL, $ES_AUTOVSCROLL, $ES_AUTOHSCROLL)

Lets say I want to keep the default style but set a different parameter for exstyle.

I can write this:

GUICtrlCreateEdit("text", 0, 0, 200, 200, BitOR($ES_WANTRETURN, $WS_VSCROLL, $WS_HSCROLL, $ES_AUTOVSCROLL, $ES_AUTOHSCROLL), $WS_EX_CLIENTEDGE)

Or I can write this:

GUICtrlCreateEdit("text", 0, 0, 200, 200, -1, $WS_EX_CLIENTEDGE)

-1 is not a magic number in autoit. It will only work on functions that specifically are coded to interpret it as a default value. If i wanted my function to interpret "pink elephant" as a default value i could but -1 is probably better :).

Edit: Woah lots of posts were made in the mean time

Finally! Someone gave me a answer without thinking I'm trying to be offensive, thank you good sir.

Didn't think that way at all... sorry if thats what it sounded like. ;) Edited by MattyD

Share this post


Link to post
Share on other sites

As an example please see the help file for GUICreate. -1 means "center" if specified for the "left" or "top" parameter for this function.

-1 might mean something completely different for another function.

Awww, I'm this is going to be a hard little code to learn.

So many variations. @_@

Thanks guise!

;)

Share this post


Link to post
Share on other sites

Ok so lets take say, GUICtrlCreateEdit

GUICtrlCreateEdit ( "text", left, top [, width [, height [, style [, exStyle]]]] )

The default style is:

BitOR($ES_WANTRETURN, $WS_VSCROLL, $WS_HSCROLL, $ES_AUTOVSCROLL, $ES_AUTOHSCROLL)

Lets say I want to keep the default style but set a different parameter for exstyle.

I can write this:

GUICtrlCreateEdit("text", 0, 0, 200, 200, BitOR($ES_WANTRETURN, $WS_VSCROLL, $WS_HSCROLL, $ES_AUTOVSCROLL, $ES_AUTOHSCROLL), $WS_EX_CLIENTEDGE)

Or I can write this:

GUICtrlCreateEdit("text", 0, 0, 200, 200, -1, $WS_EX_CLIENTEDGE)

-1 is not a magic number in autoit. It will only work on functions that specifically are coded to interpret it as a default value. If i wanted my function to interpret "pink elephant" as a default value i could but -1 is probably better :).

Thank you, this should be enough for now that I can look into.

If I need any more help with this subject I will be sure to bump this thread.

;)

Share this post


Link to post
Share on other sites

#10 ·  Posted (edited)

I also use -1 as a default parameter for some of my functions that also take values 0 to positive infinity. In that particular case, -1 is easier to account for than just any random negative number.

Kinda like a search function that I coded, one of the parameters I use is the search depth or how many folders deep should the search function run. I used 0 to indicate only within the starting folder, any positive number to indicate how many folders deep in particular, then -1 to indicate that the search should go until whatever the deepest folder level is.

Edited by omikron48

Share this post


Link to post
Share on other sites

You all are so awesome.

;)

Share this post


Link to post
Share on other sites

Kalin,

There is another use for -1 when you are addressing controls. If you use -1 in place of the ControlID, it means "use the last created control":

#include <GUIConstantsEx.au3>

$hGUI = GUICreate("Test", 500, 500)

$hLabel_First = GUICtrlCreateLabel("", 10, 10, 100, 20)
GUICtrlSetData(-1, "First") ; <<<<<<<<<<<<<<<<<<

$hLabel_Second = GUICtrlCreateLabel("", 10, 50, 100, 20)
GUICtrlSetData(-1, "Second") ; <<<<<<<<<<<<<<<<<<

GUISetState()

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch
WEnd

Saves a lot of wear and tear on the typing fingers if you use long variable names! ;)

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______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

-1 should be documented in the help file, really.

So many meaning yet no info in help file

Share this post


Link to post
Share on other sites

-2 too.


♡♡♡

.

eMyvnE

Share this post


Link to post
Share on other sites

There are ALOT of things they need to include in the helpfile, hopefully they will be updating it soon.

Share this post


Link to post
Share on other sites

Dim $ambiguity = -2
MsgBox(0, "???", $ambiguity & " = " & 4^.5)

;)

lol wat...

Share this post


Link to post
Share on other sites

There are ALOT of things they need to include in the helpfile, hopefully they will be updating it soon.

Assuming with "They" you mean the volunteers that mainly keep updating/upgrading AutoIt.

Your free in trying to do some preliminary work in the ALOT area if you like.


"Straight_and_Crooked_Thinking" : A "classic guide to ferreting out untruths, half-truths, and other distortions of facts in political and social discussions."
"The Secrets of Quantum Physics" : New and excellent 2 part documentary on Quantum Physics by Jim Al-Khalili. (Dec 2014)

"Believing what you know ain't so" ...

Knock Knock ...
 

Share this post


Link to post
Share on other sites

Assuming with "They" you mean the volunteers that mainly keep updating/upgrading AutoIt.

Your free in trying to do some preliminary work in the ALOT area if you like.

Did I say that I didn't mean "They" so you foreclaim?

God, seriously people, stop trying.

And sounds good to me.

I can help.

;)

Share this post


Link to post
Share on other sites

And sounds good to me.

I can help.

Great. Just hope you know what a valik is. ;)

"Straight_and_Crooked_Thinking" : A "classic guide to ferreting out untruths, half-truths, and other distortions of facts in political and social discussions."
"The Secrets of Quantum Physics" : New and excellent 2 part documentary on Quantum Physics by Jim Al-Khalili. (Dec 2014)

"Believing what you know ain't so" ...

Knock Knock ...
 

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  
Followers 0