【发布时间】:2016-07-02 21:00:46
【问题描述】:
我最近在 VB.NET 上编写了一个程序,例如显示 Input1 Mod Input2。这里我使用函数:
Private Function remainder(intno1 As Integer, intno2 As Integer) As Integer
Dim intresult As Integer
intresult = intno1 Mod intno2
remainder = intresult
End Function
然后我在 Button_Click 事件中调用它:
Dim intm As Integer, intn As Integer
Dim intmod As Integer
intm = Val(TextBox1.Text)
intn = Val(TextBox2.Text)
If TextBox1.Text >= TextBox2.Text Then
MsgBox("Error while computing proccess ! Please try Again.", vbOKOnly + vbCritical, "Error!")
**Stop statement**
End If
intmod = remainder(intm, intn)
RichTextBox1.Text = "The result is " & Str(intmod)
正如您在此代码中看到的,当 txt1 大于或等于 txt2 时,我使用 if 语句,然后显示消息框。在 End If 子句之前我想使用停止运行代码的语句。我的意思是停止在 Function 上执行这些过程。
我使用Stop 和End 语句,但在我调试程序后,它停止响应甚至退出程序。
我应该在这里做什么?
【问题讨论】:
-
Return或Exit Sub -
现在要做的是单击其中一个答案旁边的复选标记,以便将其从未回答列表中移出。
-
Return 对我有用。问题是 Return 因为它对其他语句有效吗?我的意思是它只对函数有用,或者对一些什么有用?
-
读取键入时弹出的 Intellisense:
Returns execution control to the code that called a Function, Sub, Get, Set, or Operator procedure.使用Return <something>从函数返回值
标签: vb.net