Jump to content

is there any way to Read the result of Func ?


Recommended Posts

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

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()

 

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2024-07-28 - Version 1.6.3.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 (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

@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

 

Link to comment
Share on other sites

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 2024-07-28 - Version 1.6.3.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 (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

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.

Link to comment
Share on other sites

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

 

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2024-07-28 - Version 1.6.3.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 (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

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.

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2024-07-28 - Version 1.6.3.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 (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

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.

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