• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 197
  • Last Modified:

Run a subroutine next?

In a sub, is there a way to run a different sub after the original sub is complete.

Private Sub Routine1()
   'after you complete this routine run Routine2
End Sub

Private Sub Routine2()
  'run this after Routine1 is completed.
End Sub
0
Gary Samuels
Asked:
Gary Samuels
  • 2
1 Solution
 
ctm5Commented:

Private Sub Routine1()

   'do something here for the first routine
   'then call the second routine
   Routine2()

End Sub


That's it!

ctm5
0
 
Carl TawnSystems and Integration DeveloperCommented:
I would have thought you mean:

    Private Sub Routine1()
       '// Do some stuff
        Routine2()
    End Sub

    Private Sub Routine2()

    End Sub

Either that or you're controlling code should just run it:

    Public Shared Main()
        Routine1()    '// Run routine 1
        Routine2()    '// Run routine 2 now that 1 has completed
    End Sub
0
 
Gary SamuelsPlant ManagerAuthor Commented:
I've noticed that changes to some variables will not change until a sub routine reaches the End Sub block and the sub routine is completely finished.

For example, I have a sub routine that is fired when a row is deleted from a datagrid. In the routine I wanted to recalculate the sum of a field because a row has been removed.  In the Sub routine I first update the table and accept the changes in the dataset, then I check the row count and see that the count remains the same as before the update and accept changes. This means that the update and accept changes will not take effect until the routine is finished; therefore I can not recalculate the sum of a field in the same routine.

I was hoping I could set up some kind of procedural programming steps such as run Routine1 first and when it is finished run Routine2. I think the answer to my question is, no you can't do that.
0
 
ctm5Commented:
I suspect a bit of faulty reasoning here.

The number of rows in a datagrid doesn't change because a row has been deleted. The row is still there -- it just doesn't have any data in it. Changes have taken place; you are just using a faulty device to measure them.

The subroutines are firing in the proper order, and yes, you can set up routine 2 to run when routine 1 is finished. I do it all the time; for years, procedural programming was all there was, and OO programming depends on it (deep down -- don't tell anyone, it's a dirty little secret).

ctm5

0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now