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 

Basic Problem with global variables and controls

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



Joined: 25 Jan 2006
Posts: 16
Location: Somewhere in Germany

PostPosted: Thu Dec 14, 2006 8:32 am    Post subject: Basic Problem with global variables and controls Reply with quote

I've got a problem with variables in controls in context with functions. I think it's a basic problem of my understanding how AHK works - but nevertheless I cannot figure out, how it works ...

I tried the following:

Code:

...
GuiTitlebarClock()
return

; -------------------------------------------------------------------------------------------------
; Toogle display of clock in titlebar
;
GuiTitlebarClock(Timerduration=1000)
{
    FormatTime, TimeString, , hh:mm:ss - ddd, dd MMM
 
    Gui, +ToolWindow +AlwaysOnTop -SysMenu
    Gui, -Caption ;
   ;*********************************************************************************************************
   ;**** Error occurs on the following line *************************************************************
    Gui, Add, Text, vTxtCurrentTime  x+10 y5, %TimeString%
   ;*********************************************************************************************************
    Gui, Show, AutoSize NoActivate xcenter y0 h18 w240, %TimeString%
 
    WinSet, TransColor, CCCCCC 255, ahk_class AutoHotkeyGUI
    SetTimer, AdjustTime, %Timerduration%
}
....


What happens? When I start the script, AHK says: Error: A control's variable must be global. The curtrent thread will exit. Specifically: vTxtCurrentTime. The error occurs in the marked line in the code excerpt ...

How can I avoid this? I made several attempts to "make the variable global" - but didn't succeed ...

Thanks
Hoppfrosch
Back to top
View user's profile Send private message
jonny



Joined: 13 Nov 2004
Posts: 3004
Location: Minnesota

PostPosted: Thu Dec 14, 2006 8:43 am    Post subject: Reply with quote

Try declaring it somewhere in the function, like this:

global TxtCurrentTime
Back to top
View user's profile Send private message
hoppfrosch



Joined: 25 Jan 2006
Posts: 16
Location: Somewhere in Germany

PostPosted: Thu Dec 14, 2006 8:47 am    Post subject: Reply with quote

Quote:
global TxtCurrentTime


Thanks! This works ...

Question But why to use TxtCurrentTime instead of vTxtCurrentTime?

I think I have to dig a little deeper into the AHK-manual ... Rolling Eyes
Back to top
View user's profile Send private message
hoppfrosch



Joined: 25 Jan 2006
Posts: 16
Location: Somewhere in Germany

PostPosted: Thu Dec 14, 2006 8:55 am    Post subject: Reply with quote

Smile Found it in the Manual:
Section: GUI - Chapter: Options for Assigning Actions and Variables to Controls

Never use foreign code without understandig it ... Wink

Thanks!
Back to top
View user's profile Send private message
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