Jump to content
Tripoz

is there any way to Read the result of Func ?

Recommended Posts

Tripoz

Hi,

i have some code like:

 


While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
         case $Button1
            test1()
            test2()
           test3()
            OP()
    EndSwitch
 WEnd


func test1()
;;;;if statement with many condition
EndFunc


Func test2()
;;;;if statement with many condition
EndFunc

Func test3()
;;;;if statement with many condition
EndFunc


FUnc OP()

;;;how to read the result of Func test1() ????

$aaa = call(Test1)

if test1() = "XXXXX" and test2() = "YYYYY" AND test3() = "zzzzz" then

consolewrite("success!")

else

consolewrite("unsuccess!")

EndFunc

 

is there any way to Read the result of each Func like i write in Func OP()?

thx for anyhelp..

 

Edited by Tripoz

Share this post


Link to post
Share on other sites
Tripoz

Look into return

im too nubie...still confuse

how can i get the result from Func test1() and write it in other Function (func OP() in my case ???

thx for any help

Share this post


Link to post
Share on other sites
water

You really need to start learning how AutoIt works. The help file and the wiki with many tutorials are good starting points.

func test1()
    ;;;;if statement with many condition
    Return "xxxx"
EndFunc


BTW:
No need to use call here

$aaa = call(Test1)

simply use

$aaa = Test1()

 

  • Like 1

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2018-06-01 - Version 1.4.9.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-01-27 - Version 1.3.3.1) - 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
Tripoz

@water thx btw..but i dont know where to start so i just writing the code for my project n i had stucked..

i change my code to be like this??its right?

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
         case $Button1
            OP()
    EndSwitch
 WEnd


func test1()
   if $kemana1 > $Kemana2 Then
      SLEEP(1000)
      ConsoleWrite("Dibawah")
      return "Dibawah"
   Else
      SLEEP(1000)
      ConsoleWrite("Diatas")
      return "Diatas"
   EndIf

EndFunc

Func OP()
$aaa = test1()

if $aaa = "Dibawah" then
    consolewrite("success!")
elseif $aaa = "Diatas" then 
    consolewrite("unsuccess!")
EndIf

EndFunc

 

Share this post


Link to post
Share on other sites
TheDcoder

Please watch Morthwart's great AutoIt tutorials!

 

TD :)

 

P.S I learned AutoIt using these videos

  • Like 1

AutoIt.4.Life Clubrooms - Life is like a Donut (secret key)

Spoiler

My contributions to the AutoIt Community

Some messages & Apologizes:

If I hurt you, Please accept my apologies, I never (regardless of the situation) mean to hurt anybody!!!

Also, I am very busy with my project so I will appear in the last row of the online list, if you want to contact me: Email@TheDcoder.xyz

Or you can have a nice chat with me in freenode, I use the same nick on freenode too!

3fHNZJ.gif

PLEASE JOIN ##AutoIt AND HELP THE IRC AUTOIT COMMUNITY!

Share this post


Link to post
Share on other sites
water

Looks good so far.
But I think your script gets more complex than needed. As test1() only contains a simple If/Then/Else I suggest to simplify to:

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Button1
            OP()
    EndSwitch
WEnd

Func OP()
    If $Kemana1 > $Kemana2 Then
        ConsoleWrite("Dibawah - success" )
    Else
        ConsoleWrite("Diatas - no success")
    EndIf
EndFunc

 


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2018-06-01 - Version 1.4.9.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-01-27 - Version 1.3.3.1) - 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
232showtime

good day @water,

im confused also with this return, question is whats the difference between a return with Msgbox and MsgBox only...

 

Script with Return+msgbox

max(3, 2)

Func max($x, $y)
    If $x > $y Then
        Return MsgBox(64, "", $x)

    Else
        Return MsgBox(64, "", $y)
    EndIf
EndFunc   ;==>max

 

Script with MsgBox only

max(3, 2)

Func max($x, $y)
    If $x > $y Then
        MsgBox(64, "", $x)

    Else
        MsgBox(64, "", $y)
    EndIf
EndFunc   ;==>max

T_T

whats the use of Return?

Edited by 232showtime

ill get to that... i still need to learn and understand a lot of codes graduated.gif

Correct answer, learn to walk before you take on that marathon.

Share this post


Link to post
Share on other sites
water
Return MsgBox(64, "", $x)

simply saves some lines of code.
Return leaves the function after having displayed the MsgBox.
Example:

Func Test($sValue)
    If $sValue <> "A" Then Return MsgBox(64, "Error", "Invalid value for $sValue!")
    ; More
    ; Statements
EndFunc

 

  • Like 1

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2018-06-01 - Version 1.4.9.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-01-27 - Version 1.3.3.1) - 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
water

Another aspect:
As the return value of MsgBox is the ID of the button pressed function Test returns this ID to the calling function.
Most of the time this information is ignored by the script.

  • Like 1

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2018-06-01 - Version 1.4.9.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-01-27 - Version 1.3.3.1) - 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
232showtime
Return MsgBox(64, "", $x)

simply saves some lines of code.
Return leaves the function after having displayed the MsgBox.
Example:

Func Test($sValue)
    If $sValue <> "A" Then Return MsgBox(64, "Error", "Invalid value for $sValue!")
    ; More
    ; Statements
EndFunc

 

this explains well, now i know how to use Return. thanks  :dance:


ill get to that... i still need to learn and understand a lot of codes graduated.gif

Correct answer, learn to walk before you take on that marathon.

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

×