是否可以调用用户使用 msgbox 定义子过程?
Is this possible to call users define sub procedure using msgbox?
例如代码:
show_box()
Function show_box()
result = MsgBox ("Please follow steps in document"vbCrLf & vbCrLf _
& "Click OK to call sum procedure" & vbCrLf & vbCrLf _
& "Click No to call substraction procedure"& vbCrLf & vbCrLf _
& "Click cancel to print hello")
Select Case result
case 1
msgbox(sum(1,2))
case 7
msgbox(substraction(4,2))
Case 2
msgbox("Hello")
End Select
END Function
sub sum(a,b)
sum = a+b
msgbox(sum)
end sub
sub substraction(a,b)
substraction = a - b
msgbox(substraction)
end sub
结果应该是:当我点击OK,然后调用sum(a,b)过程,等等。我尝试了很多次使用不同的方法,但我无法解决这个问题。
将不胜感激!!
尝试更像这样的东西:
Function sum(a, b)
sum = a + b
End Function
Function substraction(a, b)
substraction = a - b
End Function
Sub show_box()
Dim result
result = MsgBox ("Please follow steps in document" & vbCrLf & vbCrLf _
& "Click Yes to call sum procedure" & vbCrLf & vbCrLf _
& "Click No to call substraction procedure" & vbCrLf & vbCrLf _
& "Click Cancel to print hello",
vbYesNoCancel)
Select Case result
Case vbYes
MsgBox(CStr(sum(1,2)))
case vbNo
MsgBox(CStr(substraction(4,2)))
Case vbCancel
MsgBox("Hello")
End Select
End Sub
show_box()
例如代码:
show_box()
Function show_box()
result = MsgBox ("Please follow steps in document"vbCrLf & vbCrLf _
& "Click OK to call sum procedure" & vbCrLf & vbCrLf _
& "Click No to call substraction procedure"& vbCrLf & vbCrLf _
& "Click cancel to print hello")
Select Case result
case 1
msgbox(sum(1,2))
case 7
msgbox(substraction(4,2))
Case 2
msgbox("Hello")
End Select
END Function
sub sum(a,b)
sum = a+b
msgbox(sum)
end sub
sub substraction(a,b)
substraction = a - b
msgbox(substraction)
end sub
结果应该是:当我点击OK,然后调用sum(a,b)过程,等等。我尝试了很多次使用不同的方法,但我无法解决这个问题。 将不胜感激!!
尝试更像这样的东西:
Function sum(a, b)
sum = a + b
End Function
Function substraction(a, b)
substraction = a - b
End Function
Sub show_box()
Dim result
result = MsgBox ("Please follow steps in document" & vbCrLf & vbCrLf _
& "Click Yes to call sum procedure" & vbCrLf & vbCrLf _
& "Click No to call substraction procedure" & vbCrLf & vbCrLf _
& "Click Cancel to print hello",
vbYesNoCancel)
Select Case result
Case vbYes
MsgBox(CStr(sum(1,2)))
case vbNo
MsgBox(CStr(substraction(4,2)))
Case vbCancel
MsgBox("Hello")
End Select
End Sub
show_box()