Jump to content
232showtime

Help with UDF

Recommended Posts

232showtime

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.

Share this post


Link to post
Share on other sites
TheDcoder

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

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

Spoiler

My contributions to the AutoIt Community

If I have hurt or offended you in anyway, Please accept my apologies, I never (regardless of the situation) mean to do that to anybody!!!

3fHNZJ.gif

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

Share this post


Link to post
Share on other sites
232showtime

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.

Share this post


Link to post
Share on other sites
TheDcoder
Just now, 232showtime said:

I did it again and it works, I wonder why??? thats why i got confused...

Happens ;)


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

Spoiler

My contributions to the AutoIt Community

If I have hurt or offended you in anyway, Please accept my apologies, I never (regardless of the situation) mean to do that to anybody!!!

3fHNZJ.gif

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

Share this post


Link to post
Share on other sites
Subz
Quote

I already tried $param1 = 1 i received an error earlier

What do you mean you tried $param1 = 1?

Share this post


Link to post
Share on other sites
232showtime

 

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.

Share this post


Link to post
Share on other sites
Subz

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.

Share this post


Link to post
Share on other sites
232showtime

yep thanks @TheDcoder @Subz ... B)B)


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

×