13. Sequence

One of the first concepts of programming one needs to become familiar with is that code is executed in sequence. Which simply means one line of code is finished before the computer moves onto the next. For this reason, it is possible to debug and follow exactly what the computer is doing line by line in the knowledge that nothing unexpected can occur.

Thinking back to the “Load” event we began creating on the previous page we can now consider what that event should do. So what are the differences between the form we initially created and the one that we need to display when the program loads?

  1. All the Noughts and Crosses buttons need to be set blank
  2. The instruction box needs to have our initial instructions
  3. The number of Cross wins needs to be set to zero
  4. The label displaying the Cross wins needs to be updated
  5. The number of nought wins needs to be set to zero
  6. The label displaying the Nought wins needs to be updated
  7. The Play Again button needs to be disabled

And that appears to be a comprehensive list of what has to occur. Is the sequence of those events important? In other words, if I mix up the order of those tasks does it matter? What about if I switched options 3 and 4 around so that I updated the label before changing the number of cross wins?

This is what sequence is all about, recognising an appropriate order that you will execute your code in. Remember the computer cannot do anything that you haven’t told it to do, so if something doesn’t work correctly it simply cannot be the fault of the computer!

Flow of Logic
We now have a good idea of what this load event needs to do so let’s create a flow of logic that represents it accurately:

In this example you can see the START and END simply represent the beginning and end of the Private Sub where this code will reside. Within it we have two different types of sequential code. The blue ones indicate a single line of code that will perform the requested step, the green one with the extra vertical bars on each end represents the need for multiple lines of code to do that step.

Okay, now that we have an idea of what to do let’s add comments into our code that will serve as a place holder and reminder of what needs completing. Change your “Load” Sub-procedure so it looks like this:

This lesson has been a bit of an epic but it has provided us solid programmatic thinking. The approach taken in this lesson is one you should remember every time you’re trying to come up with code. Plan it, put comments in your code to give you a skeleton and then you can go about implementing it.

Leave a Comment

Your email address will not be published.

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>