Applescript文档表示,从 Yosemite 开始,处理程序的参数可以是可选的。
从“参数规格”部分:
带标签的参数可以通过在形式参数名称后面加上 :literal 来声明默认值。这样做会使参数在调用时成为可选参数。例如,这声明了一个 make 处理程序,其 with data 参数具有默认值:
on make new theClass with data theData : missing value现在可以在不提供 with data 参数的情况下调用该处理程序;处理程序将看到数据设置为指定的默认缺失值,然后可以对其进行测试并进行适当的处理。
因此,由于需要一个带有可选参数的处理程序,我尝试创建一个。我已经做到了这一点:
set theResult to Create of me given the string:"stuff", info:"this"
on Create given info:missing value, thestring:"stuff"
if info is missing value then
set present to false
else
set present to true
end if
return {present, thestring}
end Create
Run Code Online (Sandbox Code Playgroud)
它可以编译,但给出错误“变量 thestring 未定义。”
如果我只用一个参数调用它:
set theResult to Create of me given thestring:"stuff"
Run Code Online (Sandbox Code Playgroud)
我收到错误:“创建时缺少信息参数。” …
我想以返回新范围的方式将范围复制到新位置,然后我可以将其存储在变量中以供进一步处理。
我收集复制单元格的常用方法是使用 Range.Copy 方法:
Dim rCopiedRange As Range, rRangeToCopy as Range, rStartLocation as Range
Set rRangeToCopy = ActiveWorkbook.Sheets(1).Range("C4:F10")
Set rStartLocation = ActiveWorkbook.Sheets(2).Range("A2")
rRangeToCopy.Copy rStartLocation
Run Code Online (Sandbox Code Playgroud)
但由于这是一种方法,我无法将结果设置为变量并且
Set rCopiedRange = rRangeToCopy.Copy rStartLocation
Run Code Online (Sandbox Code Playgroud)
是一个语法错误。
如何将范围复制到新位置,以便将新范围(在本例中是工作表 2 的范围 A2 到 D6)存储为变量?