Search code examples
autohotkey

Unable to assign a variable to another one in AHK v1


I want to make a time recorder. What I know is not enough.

I want to make a script that will open up a MsgBox upon pressing Ctrl+Alt+PgDn, asking to record the time. If I click Yes, I get another MsgBox saying the time is recorded. After I close the MsgBox, the current time will recorded as a variable. Upon pressing Ctrl+Alt+Enter, a MsgBox would pop up, showing the last recorded time (the one which was stored in the variable).

Current code:‐

<!<^PgDn::
MsgBox, 4,Record time,Do you want to record the time?
If MsgBox Yes{
timestamp := %A Hour%   ;below, the error is written about this line
timestamp2 := %A Min%  
MsgBox time recorded.
}
else{}
return

<^<!enter::MsgBox time: %timestamp%:%timestamp2%

With this code, there is a strange error saying:‐

%A:This parameter has a variable missing its ending percent sign.

How do I fix this problem? Any answers? Thanks.

Edit:- Yeah, I was a bad asker back in the days. I had no idea that the variable was not %A Hour% or %A Min% but instead %A_Hour% and %A_Min%. Plus, no research effort was given. Really sorry.

PS this post is from the AHKv1 days. So, not new information.


Solution

  • Variable names in an expression are not enclosed in percent signs.

    A_Hour and A_Min are Built-in Variables

    <!<^PgDn::
        MsgBox, 4,Record time,Do you want to record the time?
        IfMsgBox Yes ; not "If MsgBox Yes"
        {
            timestamp := A_Hour ; expression
            timestamp2 := A_Min
            MsgBox time recorded.
        }
        ; else{
        ; do sth else
        ; }
    return
    
    <^<!enter:: MsgBox, time: %timestamp%:%timestamp2% ; this is a command (no expression)