0

I am studying Visual Basic .NET and I have a question about about goto statement

I would like to jump function to function by click button.

For example , we have UI form and there is one button "stop" and there are two functions "first" and "second" .

I can be middle of running function "one" or "two" When user click UI_BT_SAVE_RS button , just skipped one or two function and go to the end.

I would like to know that skipping two function when the users are clicking UI_BT_SAVE_RS button

For example,

In UI form we have button event and two function

    Private Sub UI_BT_SAVE_RS_Click(sender As Object, e As EventArgs) Handles UI_BT_SAVE_RS.Click
// if user click this button then go to skipped: in the one_two()

End Sub

public sub one_two()
one() // just function name
two() // just function name
skipped:
end sub

when user clicks UI_BT_SAVE_RS button, i would like to skipped one and two function and go to end which is "skipped"

is there anyway that skip and goto some part of code by button clicking event ?

thanks

4

2 回答 2

1

Do not use goto or labels in your code, make whatever would be in the skipped label a separate function/sub that gets called by the UI_BT_SAVE_RS_Click event handler instead.

UPDATE:

For example, if you have 3 methods; one(), two() and three(), like this:

Private Function one() As String
    Return "one"
End Function

Private Function two() As String
    Return "two"
End Function

Private Function three() As String
    Return "three"
End Function

Now you want your button click event handler method to call one() and three(), then you just make a call to each function, like this:

Private Sub UI_BT_SAVE_RS_Click(sender As Object, e As EventArgs) Handles UI_BT_SAVE_RS.Click
    Dim returnValue As String = one()
    Dim returnValue2 As String = three()
End Sub

Note: This gives the control to call whatever permutation of the one(), two() and three() logic you want.

于 2013-08-15T02:43:39.413 回答
0

您可以使用全局 var 来检查对 one() 和 two() 的每次调用,或者只检查一次。在一两次中,您也可以检查该变量,以便在需要时退出这些变量。

Public DoStuff as Boolean = True

Private Sub UI_BT_SAVE_RS_Click(sender As Object, e As EventArgs) Handles UI_BT_SAVE_RS.Click
    DoStuff = False
End Sub

Public Sub one_two()
    If DoStuff = True then one() // just function name
    If DoStuff = True then two() // just function name
End Sub
于 2013-08-15T07:15:52.080 回答