applescript计算器不起作用

samrockw22

我做了一个计算器,它应该可以工作,但是不可以。唯一起作用的部分是添加。这是我的代码:

   my Calculator()
on Calculator()
    display dialog "Calculator" buttons {"Add", "Multiply", "Divide"}
    if button returned of the result is "Add" then
        display dialog "What plus What?" default answer ""
        set a to (text returned of result)
        if a is equal to "q" then
            return
        end if
        display dialog "Next number" default answer ""
        set b to (text returned of result)
        set c to a + b
        display dialog "The answer is " & c buttons {"Start Again", "Quit"}
        if button returned of the result is "Quit" then
            return
        else
            my Calculator()
        end if
    end if
    if button returned of the result is "Multiply" then
        display dialog "What times what?" default answer ""
        set a to (text returned of result)
        if a is equal to "q" then
            return
        end if
        display dialog "Next number" default answer ""
        set b to (text returned of result)
        set c to a * b
        display dialog "The answer is " & c buttons {"Start Again", "Quit"}
        if button returned of the result is "Quit" then
            return
        else
            my Calculator()
        end if
    end if
    if button returned of the result is "Divide" then
        display dialog "What divided by what?" default answer ""
        set a to (text returned of result)
        if a is equal to "q" then
            return
        end if
        display dialog "Next number" default answer ""
        set b to (text returned of result)
        set c to a / b
        display dialog "The answer is " & c buttons {"Start Again", "Quit"}
        if button returned of the result is "Quit" then
            return
        else
            my Calculator()
        end if
    end if
end Calculator
end
   end

它是一个applescript代码。抱歉,这是一个nooby问题,但我需要帮助。谢谢!

克雷格·史密斯

您正在使用三个if/end if语句来处理返回的按钮,您应该只使用单个if/end,并else if在两者之间利用我已经修改了您的代码以对其进行修复,并注释掉了不正确的区域。

例如:

   my Calculator()
on Calculator()
    display dialog "Calculator" buttons {"Add", "Multiply", "Divide"}
    if button returned of the result is "Add" then
        display dialog "What plus What?" default answer ""
        set a to (text returned of result)
        if a is equal to "q" then
            return
        end if
        display dialog "Next number" default answer ""
        set b to (text returned of result)
        set c to a + b
        display dialog "The answer is " & c buttons {"Start Again", "Quit"}
        if button returned of the result is "Quit" then
            return
        else
            my Calculator()
        end if
    else if button returned of the result is "Multiply" then
        display dialog "What times what?" default answer ""
        set a to (text returned of result)
        if a is equal to "q" then
            return
        end if
        display dialog "Next number" default answer ""
        set b to (text returned of result)
        set c to a * b
        display dialog "The answer is " & c buttons {"Start Again", "Quit"}
        if button returned of the result is "Quit" then
            return
        else
            my Calculator()
        end if
    else if button returned of the result is "Divide" then
        display dialog "What divided by what?" default answer ""
        set a to (text returned of result)
        if a is equal to "q" then
            return
        end if
        display dialog "Next number" default answer ""
        set b to (text returned of result)
        set c to a / b
        display dialog "The answer is " & c buttons {"Start Again", "Quit"}
        if button returned of the result is "Quit" then
            return
        else
            my Calculator()
        end if
    end if
end Calculator
end
   end

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章