Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

Getting a Gui Variable Value in a Function


  • Please log in to reply
5 replies to this topic
rockum
  • Members
  • 23 posts
  • Last active: Jul 11 2013 10:50 PM
  • Joined: 20 Dec 2007
I know I must be missing something simple, but how do I get the variable QuoteText to showup in the function's message box?

gui, Add, Text, x16 y13 w190 h220 vQuoteText +Smooth +VScroll +BackgroundTrans +BS_MULTILINE ,
gui, show, x100 y100 w220 h250
GuiControl, , QuoteText, "Happy Days are likely Ahead"
Return

ShowStuff(num1, num2)
{
global
msgbox, %num1% and %num2%
msgbox, %QuoteText%
}
return

F1::
Showstuff(4, 5)
return

Why doesn't this work?

sinkfaze
  • Moderators
  • 6367 posts
  • Last active: Nov 30 2018 08:50 PM
  • Joined: 18 Mar 2008
For one thing you didn't submit the GUI:

Gui, Add, Text, x16 y13 w190 h220 vQuoteText +Smooth +VScroll +BackgroundTrans +BS_MULTILINE , 
Gui, show, x100 y100 w220 h250 
GuiControl, , QuoteText, "Happy Days are likely Ahead" 
Return 

ShowStuff(num1, num2) 
{ 
global 
msgbox, %num1% and %num2% 
msgbox, %QuoteText% 
} 
return 

F1:: 
[color=red]Gui, Submit[/color]
Showstuff(4, 5) 
return


rockum
  • Members
  • 23 posts
  • Last active: Jul 11 2013 10:50 PM
  • Joined: 20 Dec 2007
It still doesn't seem to work, but thank you for pointing out one of the problems in the script.

MasterFocus
  • Moderators
  • 4323 posts
  • Last active: Jan 28 2016 01:38 AM
  • Joined: 08 Apr 2009
EDIT: Nevermind, sinkfaze's following post provides the solution.

-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

Antonio França -- git.io -- github.com -- ahk4.net -- sites.google.com -- ahkscript.org

Member of the AHK community since 08/Apr/2009. Moderator since mid-2012.


sinkfaze
  • Moderators
  • 6367 posts
  • Last active: Nov 30 2018 08:50 PM
  • Joined: 18 Mar 2008
My apologies, to get the text of a Text control you must use GuiControlGet:

If the target control has an associated variable, specify the variable's name as the ControlID (this method takes precedence over the ones described next). For this reason, it is usually best to assign a variable to any control that will later be accessed via GuiControl or GuiControlGet, even if that control is not input-capable (such as GroupBox or Text).


Gui, Add, Text, x16 y13 w190 h220 vQuoteText +Smooth +VScroll +BackgroundTrans +BS_MULTILINE , 
Gui, show, x100 y100 w220 h250 
GuiControl, , QuoteText, "Happy Days are likely Ahead" 
Return 

ShowStuff(num1, num2) 
{ 
global 
msgbox, %num1% and %num2% 
msgbox, %QuoteText% 
} 
return 

F1::
Gui, Submit
[color=red]GuiControlGet, QuoteText, , QuoteText, Text[/color] 
Showstuff(4, 5) 
return


rockum
  • Members
  • 23 posts
  • Last active: Jul 11 2013 10:50 PM
  • Joined: 20 Dec 2007
Thank works. Thanks guys.