刚学编程,请教个很傻的自定义函数问题,谢谢!
Private Sub CommandButton1_Click()
Dim a As String
a = "工程部"
a = translate(a)
MsgBox a
End Sub
Public Function translate(fox As String) As String
If fox = "采购部" Then
fox = "Purchasing"
ElseIf fox = "工程部" Then
fox = "Engineering"
ElseIf fox = "财务部" Then
fox = Finance
Else
fox = "Can't traslate!"
End If
End Function
上面的程序运行了,结果跳出来却是空的,为什么呀?我单步运行了,自定义函数执行了,fox也赋值正确,为什么最后显示的结果不是Engineering?难道自定义函数的值没有成功返回?请赐教!
[解决办法]
Public Function translate(fox As String) As String
If fox = "采购部" Then
translate = "Purchasing"
ElseIf fox = "工程部" Then
translate = "Engineering"
ElseIf fox = "财务部" Then
translate = Finance
Else
translate = "Can't traslate!"
End If
End Function
Private Sub CommandButton1_Click()
Dim a As String
a = "工程部"
a = translate(a)
MsgBox a
End Sub
'这样就OK了!
[解决办法]
Public Function translate(vbref fox As String) As String
用vbref才能返回
[解决办法]