按键精灵怎么使用自定义函数返回值? a i MessageBox i Function a(i) i=100 End Function 就是想弹出100

a i
MessageBox i
Function a(i)
i=100
End Function
就是想让它弹出的是100
怎么获得自定义函数中的值呢?

用程序代码设置即可,具体如下:

1、Function NumAdd(a, b)
NumAdd = a + b
End Function
MsgBox NumAdd(1, 1)

2、c = 123
dd = 函数(55, c)//参数代入函数内,可以是常量,也可以是变量

Function 函数(a,b)//括号里面就是参数,用变量代替,这里不能用常量
If a > b Then
函数 = 1//这就是返回值.
ElseIf a < b Then
函数 = 2//不同的情况返回不同的值
Else
函数 = 3
End If
End Function
温馨提示:答案为网友推荐,仅供参考
第1个回答  推荐于2018-02-26
以下是示例:

Function fun_a(i)
fun_a = i*100
End Function
MsgBox fun_a(10)

提示:自定义函数返回值语法如下:

Function 函数名(参数)
。。。。(你的代码)
函数名 = 返回值
End Function追问

可以返回多个值吗?例如我想返回一个坐标,或者更多的参数

追答

如果想要返回多个值,可能将值放在数组里,然后将这个数组作为返回值,以下是示例:

Function fun_a(i)
Dim a(2)
a(0) = i * 10
a(1) = i * 100
fun_a = a
End Function
arr = fun_a(10)
MsgBox "X坐标: " & arr(0) & ", Y坐标:" & arr(1)

本回答被提问者和网友采纳
第2个回答  2012-10-17
MSGBOX a(i)
相似回答