[AHK-] Function vs. Label / Global Variable

看板EzHotKey作者 (張昱珩)時間15年前 (2010/08/29 19:43), 編輯推噓0(000)
留言0則, 0人參與, 最新討論串1/1
※ [本文轉錄自 EZsoft 看板 #172UtjbO ] 作者: gt6174 (張昱珩) 看板: EZsoft 標題: Re: [請益] Autohotkey 指令 時間: Mon Oct 8 16:44:24 2007 ※ 引述《gt6174 (張昱珩)》之銘言: 請問一下,像這篇沒有人回答,我就懂了, 可以自 D 嗎? 可以的話,我就把這系列文都刪囉! ※ 引述《gt6174 (張昱珩)》之銘言: : 不知道能不能 PO 在這個板? : 這個板高手雲集,所以先 PO 在這個板囉!如果不行,請推文告知,或請板主刪除。 : 問題一: : 請問 AutoHotkey 的 Function() 和 Label: 有什麼差別? : 問題二: : 請問 Function() 下的 Global 作用是什麼? : AutoHotkey 附的說明檔對於 Function 下的 Global 指令的說明如下: : Although a function may call itself recursively, if it passes one of its own : local variables or non-ByRef parameters to itself ByRef, the new layer's : ByRef parameter will refer to its own local variable of that name rather than : the previous layer's. However, this issue does not occur when a function : passes to itself a global variable, static variable, or ByRef parameter. : - Local and Global Variables - : Local Variables: : All variables referenced or created inside a function are local by default : (except built-in variables such as Clipboard, ErrorLevel, and A_TimeIdle). : Each local variable's contents are visible only to lines that lie inside the : function. Consequently, a local variable may have the same name as a global : variable and both will have separate contents. Finally, all local variables : start off blank each time the function is called. : Global variables: : To refer to an existing global variable inside a function (or create a new : one), declare the variable as global prior to using it. : 雖然看了 Help File,但還是搞不懂 @@" -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 61.60.0.162

10/08 13:28,
不要自d啦...這樣別人才能參考啊
10/08 13:28

10/08 13:30,
置底文有講喔^^a
10/08 13:30
那我自己把解答寫詳細一點: 問題一:請問 AutoHotkey 的 Function() 和 Label: 有什麼差別? 答:function 有 return value,要傳入參數。 label 相當於 subrutine,可以沒有 return value,也可以不用傳入參數。 P.S: 這是 ESMania 論壇 koala 回答的。 問題二:請問 Function() 下的 Global 作用是什麼? 答:AutoHotkey 預設 Function 裡的變數與 Function 外的變數是各自獨立的, 亦即: Value1 := 357 Gosub Label_1 Label_1: Function_135() Return Function_135() { Value1 := 123 MsgBox, %Value1% Return } MsgBox, %Value1% 這兩個 Message Box 顯示出來的 Value1 值不一樣。 一個是 357,一個是 123。 欲使外部的 Value1 和 Function 內的 Value1 為同一個 Value1, 則要在 Function 中加入 Global 指令。 如把上述的 Function_135 改成如下: Function_135() { Global Value1 := 123 MsgBox, %Value1% Return } 如此一來,這兩個 Value1 就會變成一樣了。 Message Box 顯示出來的值也都是會 123。 -- ▄▄ ▄▄ ▄▄ ▄ ▄ ▄ ▄▄ ▄▄ ▄▄ ▄▄ ▄ ▄▄ ▄▄▄▄ ▄▄ ▄▄ -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 61.60.0.162 ※ 編輯: gt6174 來自: 218.167.45.240 (10/08 23:42)

10/13 01:03,
推一個呱
10/13 01:03
※ 編輯: gt6174 來自: 61.60.0.162 (11/02 17:05) -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 114.42.221.238 ※ 編輯: gt6174 來自: 211.21.127.209 (07/30 20:21)
文章代碼(AID): #1CUaVeJN (EzHotKey)