TM80
TM80

Reputation: 123

Calling another sub then returning to first sub to continue (vb.net)

Is it possible to have a function that cuts to another function and when that step is complete return to the first fuction again...? at the moment I can only switch to another sub but not return and continue where I left example:

Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click

        msgbox("Hello step 1")

        Call SECONDSTEP()

        msgbox("Hello step3")
end sub

Upvotes: 0

Views: 1810

Answers (2)

Jitendra Joshi
Jitendra Joshi

Reputation: 78

Your execution will always return to calling function. in this example three message box display in sequence step1, step2, step3. But if sub function contain close() then execution will not return to calling function.

Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        MsgBox("step 1")

        Call SECONDSTEP()

        MsgBox("step3")
    End Sub

    Private Sub SECONDSTEP()
        MsgBox("step2")
    End Sub

Upvotes: 3

JaggenSWE
JaggenSWE

Reputation: 2094

Well, if you do something like this:

Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click

        msgbox("Hello step 1")

        Dim a As Integer
        a = GiveMeSomeAnswers(21,2)

        msgbox("The answer is"& a)
End Sub

Private Function GiveMeSomeAnswers(x As Integer, y As Integer) As Integer

   Return x*y

End Sub

If will run the first messagebox (Hello Step 1) and then run the second function which multiplies x and y and then return back to the first method and give you a second messagebox that says (The answer is 42).

Upvotes: 3

Related Questions