Sign in to follow this  
Followers 0
..t.k.

Function Within A Function?

9 posts in this topic

Hi,

I'd like to know how to put a function within a function - or any other method of doing this...!

I'm trying to make a script compatible for both WinXP and W2k.

The reason they differ, is because of a registry setting depending on the OS version.

So what I'd like to do is this:

If @OSVersion = 'WIN_2000' then
   _Win2k()
elseif @OSVersion = 'WIN_XP' then
   _Win_XP()
endif


FUNC _Win2k()
   msgbox (0, "", "Win2k" ) ;instead of msgbox, Several other functions goes here!
Endfunc ;;; Win2k

FUNC _Win_XP()
   msgbox (0, "", "WinXP" ) ;instead of msgbox, Several other functions goes here!
EndFunc ;;; WinXP

Can anyone guide me in the right direction here?

And to those of you who wasn't figured it out - I'm no programmer...!!! :D

..t.k.


[font="Geneva"]..t.k.[/font]

Share this post


Link to post
Share on other sites



Uhh...? What's wrong with that? You do realize MsgBox is a function right? So you are already calling a function in a function.

Share this post


Link to post
Share on other sites

You don't have to put a function in a function.

If you create the 2nd function elsewhere and call it from the 1st

(like the msgbox function), it will work fine.

Share this post


Link to post
Share on other sites

Aye, more examples of func in a func.

If @OSVersion = 'WIN_2000' then
  _Win2k()
elseif @OSVersion = 'WIN_XP' then
  _Win_XP()
endif


FUNC _Win2k()
tip()
  msgbox (0, "", "Win2k" );instead of msgbox, Several other functions goes here!
Endfunc;;; Win2k

FUNC _Win_XP()
tip()
  msgbox (0, "", "WinXP" );instead of msgbox, Several other functions goes here!
EndFunc;;; WinXP

func tip()
tooltip("Please click the OK button",@desktopwidth/2-60,@desktopheight/2-60)
endfunc

AutoIt3, the MACGYVER Pocket Knife for computers.

Share this post


Link to post
Share on other sites

The only thing you can't do is define a function within another function. Outside of this limitation you can craete as many user defined functions as you need, and use them in any script where they are defined.


[font="Optima"]"Standing in the rain, twisted and insane, we are holding onto nothing.Feeling every breath, holding no regrets, we're still looking out for something."[/font]Note: my projects are off-line until I can spend more time to make them compatable with syntax changes.

Share this post


Link to post
Share on other sites

Thanks, pek!

I realize I've explained my problem a bit poorly.

Define a function within another function is excactly what I tried to do.

Anyway, when that's not possible - what do I do to get around that??

..t.k.


[font="Geneva"]..t.k.[/font]

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

Whoops!

Didn't read scriptKitty and SlimShady's answers thoroughly enough.

Sorry, I'll stop nagging you for now and do some more testing.

Then I'll nag you some more after that....!! :D

..t.k.

Edited by ..t.k.

[font="Geneva"]..t.k.[/font]

Share this post


Link to post
Share on other sites

Thanks to all of you!

I've got it working now!! :D

..t.k.


[font="Geneva"]..t.k.[/font]

Share this post


Link to post
Share on other sites

I'm glad.

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