Main program calls subs


You have a relatively complex program. It's too big to think about all at once.


Break the program into subs. The main program coordinates passing data between the subs.


An example:

  1. Private Sub cmdRun_Click()
  2.     Dim quality As String
  3.     Dim size As String
  4.     Dim region As String
  5.     Dim price As Single
  6.     'Input
  7.     getInput quality, size, region
  8.     'Processing
  9.     computePrice quality, size, region, price
  10.     'Output
  11.     output price
  12. End Sub
  13. 'Input
  14. Sub getInput(quality As String, size As String, region As String)
  15. ...
  16. End Sub
  17. 'Processing
  18. Sub computePrice(quality As String, size As String, region As String, price As Single)
  19. ...
  20. End Sub
  21. 'Output
  22. Sub output(price As Single)
  23. ...
  24. End Sub
The main program coordinates the subs. getInput fills quality, size, and region. The main program sends those values to computePrice, which fills price, and so on.

You can write and debug getInput without thinking about the rest of the program. This reduces screaming.

Referenced in: