Sign in to follow this  
Followers 0
Arthur Jay

Sub-routines

13 posts in this topic

Can you write sub-routines in this language? If so, where can I learn how to do so?

Arthur jay

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Can you write sub-routines in this language? If so, where can I learn how to do so?

Arthur jay

Look up Function in the help file

Edited by gafrost

SciTE for AutoItDirections for Submitting Standard UDFs

 

Don't argue with an idiot; people watching may not be able to tell the difference.

 

Share this post


Link to post
Share on other sites

Can you write sub-routines in this language? If so, where can I learn how to do so?

Arthur jay

No, AutoIt does not allow functions in the local scope - all functions are global.

Share this post


Link to post
Share on other sites

Look up Function in the help file

So I went to Function Reference and found no reference to sub-routine. I searched for "function" and got 391 hits. Can you be more specific?

Share this post


Link to post
Share on other sites

So I went to Function Reference and found no reference to sub-routine. I searched for "function" and got 391 hits. Can you be more specific?

some languages use the term sub-routine, some use the term function

AutoIt has Functions


SciTE for AutoItDirections for Submitting Standard UDFs

 

Don't argue with an idiot; people watching may not be able to tell the difference.

 

Share this post


Link to post
Share on other sites

So I went to Function Reference and found no reference to sub-routine. I searched for "function" and got 391 hits. Can you be more specific?

Keyword: Func...EndFunc

Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

some languages use the term sub-routine, some use the term function

AutoIt has Functions

OK, call them whatever you want. What I need to do is execute a specific bunch of functions that produce a desired result. Typically, in a main program you set some parameters, call the sub-routine to operate as needed, then use that result in the subsequent steps in the main program. It saves having to repeat lines of code that do repetitive work.

Now, can this language do that?

Arthur Jay

Share this post


Link to post
Share on other sites

OK, call them whatever you want. What I need to do is execute a specific bunch of functions that produce a desired result. Typically, in a main program you set some parameters, call the sub-routine to operate as needed, then use that result in the subsequent steps in the main program. It saves having to repeat lines of code that do repetitive work.

Now, can this language do that?

Arthur Jay

Help -> Index tab -> func :)

Share this post


Link to post
Share on other sites

OK, call them whatever you want. What I need to do is execute a specific bunch of functions that produce a desired result. Typically, in a main program you set some parameters, call the sub-routine to operate as needed, then use that result in the subsequent steps in the main program. It saves having to repeat lines of code that do repetitive work.

Now, can this language do that?

Arthur Jay

How often do you want to get the answer? :)

Func...EndFunc


Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

OK, call them whatever you want. What I need to do is execute a specific bunch of functions that produce a desired result. Typically, in a main program you set some parameters, call the sub-routine to operate as needed, then use that result in the subsequent steps in the main program. It saves having to repeat lines of code that do repetitive work.

Now, can this language do that?

Arthur Jay

As @jpm said, the key words are Func and EndFunc. These two words define a User Defined Function

An example is below...

Func _EndProgram()

    If $iErrorFlg > 0 Then

        Exit $iErrorFlg

    Else

        Exit

    Endif
EndFunc  ;==>_EndProgram

You can call this UDF directly or conditionally. A conditional example follows.

If NOT FileExists ($sFile) Then

    _EndProgram()

EndIf

Gene :)

Note there are a number of UDFs supplied with AutoIt. In the Help file scroll all the way to the bottom in the left panel.


[font="Verdana"]Thanks for the response.Gene[/font]Yes, I know the punctuation is not right...

Share this post


Link to post
Share on other sites

How often do you want to get the answer? :)

Func...EndFunc

Hmmm...maybe you could write a function to answer the question? It would save the aforementioned repetitive work. :)

JPC :mellow:

Share this post


Link to post
Share on other sites

Hmmm...maybe you could write a function to answer the question? It would save the aforementioned repetitive work. :)

JPC :mellow:

What's still not clear to me is the flow of the program. In some other languages, you define all the sub-routines first, and then write the main program that calls these as needed. I have written menu-based programs for control of test equipment in which the execution is essentially endless. You just bounce around doing sub-routines until you are through with the day's work. I don't see that type of structure here yet, but I'll keep on trying. I'll have to bear with being a newbie subject to ritual in the process.

Arthur Jay

Share this post


Link to post
Share on other sites

Hmmm...maybe you could write a function to answer the question? It would save the aforementioned repetitive work. :)

JPC :mellow:

Good Idea!

DIM $AsManyTimesAsItTakes = ???; Your number here
DIM $ThresholdForCrap = ???; Your number here

$WhatSubRoutine = _WhatFunction()

Func _WhatFunction($PFA)

If Not $PFA Then
For $i = 1 to $AsManyTimesAsItTakes
MsgBox(0, "Look Here!", "RTFM - Func")
If $i > $ThresholdForCrap Then

Return("Threshold For Crap Exceeded")
ExitLoop
EndIf
Next

Else
$PFA = "Pay Fu??ing Attention"
MsgBox(0, "Look Here!", $PFA)
EndIf

EndFunc

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