Jump to content

Exactly, what does -1 mean


Kalin
 Share

Recommended Posts

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.

Link to comment
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.

Link to comment
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.

;)

Link to comment
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.

Edited by water

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
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 :).

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
Link to comment
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!

;)

Link to comment
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.

;)

Link to comment
Share on other sites

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

  • Moderators

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

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

  • 2 weeks later...

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

Link to comment
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.

;)

Link to comment
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 ...
 

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