【发布时间】:2016-05-13 14:21:29
【问题描述】:
我正在为一位朋友创建一个 Visual Basic 应用程序。无论如何,我正在尝试创建一个函数,该函数将“退出子”返回给调用该函数的子。我已经通过返回一个像 1 或 2 这样的值并在调用 sub 时插入一个 if 来解决这个问题。只是想知道是否有一个我还没有学过的返回退出子的简写。
Private Sub Button1.click() Handles Button1.Click
tryactive()
endsub
Private Function tryactive()
Try
AppActivate("your aplication")
Catch ex As Exception
Dim msgboxresponse = MsgBox("please start your application", 0, "Can't find your application")
If msgboxresponse = MsgBoxResult.Ok Then
Exit Sub <------ this is the problem i want to send this back to calling sub
End If
End Try
End Function
代码更大,按钮也更多。这就是为什么我要问是否有更好的方法来做到这一点。任何帮助表示赞赏。
【问题讨论】:
-
我很确定在 VB.NET 中一个函数必须返回一个类型,否则它是一个
Sub。
标签: vb.net