Jump to content

Help with UDF


Recommended Posts

Hello,

I got little problem with this UDF found in wiki, Just copy paste from wiki and got an error, got really confused this time.

#include <MsgBoxConstants.au3>

testme()
Func testme($param1, $param2 = "nothing", $param3 = 5)
    MsgBox($MB_OK, "", "Parameter one is required. The value of Parameter 1 is " & $param1 & @CRLF & _
            "Parameter 2 is optional. The value of Parameter 2 is " & $param2 & @CRLF & _
            "Parameter 3 is optional. The value of Parameter 3 is " & $param3)
EndFunc   ;==>testme

;"C:\Users\user\Desktop\Script\UserDefinedFunction.au3"(4,55) : error: testme() called by a previous line with 0 arg(s). Min = 1. ;First previous line calling this Func is 3.
;Func testme($param1, $param2 = "nothing", $param3 = 5)

 

Edited by 232showtime
I dont understand the error and why its not workin...

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

Isn't the first parameter required? :blink:

#include <MsgBoxConstants.au3>

testme("required")
Func testme($param1, $param2 = "nothing", $param3 = 5)
    MsgBox($MB_OK, "", "Parameter one is required. The value of Parameter 1 is " & $param1 & @CRLF & _
            "Parameter 2 is optional. The value of Parameter 2 is " & $param2 & @CRLF & _
            "Parameter 3 is optional. The value of Parameter 3 is " & $param3)
EndFunc   ;==>testme

 

Edited by TheDcoder
Added code snippet

EasyCodeIt - A cross-platform AutoIt implementation - Fund the development! (GitHub will double your donations for a limited time)

DcodingTheWeb Forum - Follow for updates and Join for discussion

Link to comment
Share on other sites

oh shoot, I already tried $param1 = 1 i received an error earlier, I did it again and it works, I wonder why??? thats why i got confused...

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

 

I declared $param1 = 1 and got an error, I copy paste again the code and declared $param1 = 1 and it worked, thats why I got confused.:P

Func testme($param1=1, $param2="Nothing", $param3=3)

MsgBox($MB_OK, "", "Parameter one is required. The value of Parameter 1 is " & $param1 & @CRLF & _
            "Parameter 2 is optional. The value of Parameter 2 is " & $param2 & @CRLF & _
            "Parameter 3 is optional. The value of Parameter 3 is " & $param3 )

EndFunc

 

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

That would mean $param1 is no longer required, it's optional, if you look at Dcoders post# 2 above, the $param1 variable is required, which means you must give $param1 a value e.g. testme("Here is Param1").  Hope that made sense.

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