Jump to content
Sign in to follow this  

Function questions

Recommended Posts


Question 1

Say I have a function (N1) that within it uses a command that requires 3 inputs (X,Y,Z)

Now what I want is to be able to use something (N2) to get X,Y and automatically place it into N1

So I could type something along the lines of

N2 (AB,CD)

N2 (GE,SG)

N2 (WD,XD)

which would then run function N1 three times, filling in the X and Y variables into N1 automatically. Hopefully that makes sense.

Question 2

This isn't really important but I'm curious so I'll ask. Say someone is able to help me figure out Question 1 and I really like how N2 works and want to use it often. How could I make N2 (and I guess by extension N1) available for use at all times, even if I start another script, besides rewriting the code manually for each new script.

Share this post

Link to post
Share on other sites


Welcome to the AutoIt forum. :x

Second question first. You save the code you want to reuse as a file and then use the #include directive to add it to your new script. This inserts the contents of that file into the new script at the point of the directive when the script is run or compiled. You can then call functions in that file as if they were in the new script - although of course you cannot actually see them. More details are in the Help file under "#include"

Now to the first question. Just use another function as you suggested in your pseudo-code:

; Determine the 3 parameters using function _N2
$iFirst  = _N2(2, 2) ; should return 4
$iSecond = _N2(2, 3) ; should return 6
$iThird  = _N2(4, 5) ; should return 20

; Pass them to function _N1
$iResult = _N1($iFirst, $iSecond, $iThird)
; Should return 30
MsgBox(0, "First Result", $iResult)

; And so should this where we determine the parameter values directly
$iResult = _N1(_N2(2, 2), _N2(2, 3), _N2(4, 5))
MsgBox(0, "Second Result", $iResult)

; Functions

; This function adds the 3 parameters
Func _N1($vA, $vB, $vC)

    Return ($vA + $vB + $vC)


; This function multiplies the 2 parameters
Func _N2($vA, $vB)

    Return ($vA * $vB)


Please ask if you have any questions on the code. :P


P.S. Have you read the tutorials that that you can find here and here - they will help you get over the first few bumps in the road. :shifty:

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:


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

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