AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

The use of Global

 
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Ask for Help
View previous topic :: View next topic  
Author Message
Guest






PostPosted: Tue May 13, 2008 5:10 pm    Post subject: The use of Global Reply with quote

Can You have the "Global-definition" in the begining of the script
or
Do You must have it inside the function?

Ex 1 - in the begining
Global var1

Var1 = ........
Function1
ExitApp

Function1()
(
...... Var1 + ......
)


Ex 2 - in the Functions
Var1 = .....
Function1
ExitApp

Function1()
(
Global var1

...... Var1 + ......
)
Back to top
TheIrishThug



Joined: 19 Mar 2006
Posts: 363

PostPosted: Tue May 13, 2008 8:35 pm    Post subject: Reply with quote

Anything outside of a function is in the main scope. Once inside a function, you are inside the function's scope. You use global in a function to access variables in the main scope. This should be a good example to show you how it works:
Code:
var1 = global scope
var2 = global scope
func1()
return

func1()
{
  global var1
  msgbox, func1`nvar1=%var1%`nvar2=%var2%
  var1 .= "-func1"
  var2 .= "-func1"
  msgbox, func1`nvar1=%var1%`nvar2=%var2%
  func2()
}

func2()
{
  global var1, var2
  msgbox, func2`nvar1=%var1%`nvar2=%var2%
}
Back to top
View user's profile Send private message Visit poster's website AIM Address
Guest






PostPosted: Wed May 14, 2008 9:28 am    Post subject: Reply with quote

Thank´s

Why do You use "Return" and not ExitApp in the end of the mainscript?

Do You need anything in the end of the mainscript?
Back to top
Guest






PostPosted: Wed May 14, 2008 9:57 am    Post subject: Reply with quote

??
Back to top
TheIrishThug



Joined: 19 Mar 2006
Posts: 363

PostPosted: Wed May 14, 2008 1:49 pm    Post subject: Reply with quote

Force of habit carried over from other languages.
Return wrote:
If there is no caller to which to return, Return will do an Exit instead.
Back to top
View user's profile Send private message Visit poster's website AIM Address
Display posts from previous:   
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Ask for Help All times are GMT
Page 1 of 1

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group