Passing variables to function

Get help with using AutoHotkey and its commands and hotkeys
Posts: 5
Joined: 22 Nov 2019, 04:23

Passing variables to function

25 Nov 2019, 10:07

Hello All,

Is it possible to pass variables to a function? Because i can't seem to get it to work.

Code: Select all

SetTimer, UpdateTime, 250
task = Idle
LCtime = %Time%
RLCtime = %A_Now%

Gui, Add, Button, x10 y10 h50 w50 gDoSomething, Button That Does Something
Gui, Add, Text, x5 y35 w100 h20 +Center, Clocked Time
Gui, Add, Text, x150 y35 w160 h20 +Center, Clocked Project
Gui, Add, Text, x5 y50 w100 h20 +Center Velapsed, 00:00:00
Gui, Add, Text, x150 y50 w160 h20 +Center vtsk, %task%
Gui, Show


 IniRead, oldTime, myProjects.ini, %Section%, %Key%
 MsgBox, %DurationText% have elapsed.
 newTime := oldTime + DurationText
 iniwrite, %Newtime%, myProjects.ini, %Section%, %Key%

Rawelap := A_Now - RLCtime, seconds			;calculates elapsed time, in seconds
Transform hr,floor, (Rawelap/3600)			;calculates hours of elapsed time
Transform min,floor, (Rawelap/60) - hr*60	;calculates minutes of elapsed time
sec := Rawelap - min*60 - hr*3600			;calculates seconds of elapsed time
If ( sec < 10 )								;adds a leading 0 to always keep seconds at 2 digits
   sec = 0%sec%
If ( min < 10 )								;adds a leading 0 to always keep minutes at 2 digits
   min = 0%min%
DurationText=%hr%:%min%:%sec%				;concatenates the elapsed time string
GuiControl,,elapsed, %DurationText%			;updates elapsed time display
GuiControl,,Time,%Time% 					;updates current time
GuiControl,,lastchange, %LCtime%			;updates Last Change time
GuiControl,,tsk, %Task%						;updates task name
This is my code. Im trying to display the elapsed time in a msgbox.
Posts: 152
Joined: 04 Oct 2013, 03:07
Location: Germany near Cologne

Re: Passing variables to function

26 Nov 2019, 02:36

as the msgbox command is in a function you must pass the variable as parameter or as global

User avatar
Posts: 369
Joined: 18 Apr 2014, 19:05
GitHub: Chunjee

Re: Passing variables to function

26 Nov 2019, 10:19

You passed "Accounts" and "Count" as parameters Section and Key

Your function tries to make use of DurationText but that variable is not accessible inside the function unless you make it a global function. By default ahk functions do not have access to the global scope.

Return to “Ask For Help”

Who is online

Users browsing this forum: flyingDman, Google [Bot], honarjoo, Odlanir, Sashkon, WOlfen and 106 guests