17. Debugging

Programming can be an absolute frustration. When errors occur it’s easy to lose enthusiasm and confidence, but take heart:

“Testing proves a programmer’s failure. Debugging is the programmer’s vindication.”
- Boris Beizer

When your program falls over (and it will!) you simply need to revise your code carefully and methodically and use the resources at your disposal to work out why it fell over.

The code I provided to you in the previous section was not correct and you probably realised this quite quickly:

Visual Basic is very good at recognising when something isn’t quite right and subsequently trying to give you ideas on how to fix it. The problem with the code we’ve tried to write is that the word “blank” means nothing to the programming language. If we want the text inside our button to be blank then we need to consider it’s data type.

The string data type can contain any amount of characters and any type of character. The word “String” simply refers to lots of characters “strung” together. When altering the contents of a variable that is of the data type “String” one MUST have the string enclosed in double quotes, i.e:

but1.Text = "blank"

But this, however, would put the word “blank” into the Text property which is not at all what we’re after…if we want the Text property to contain no text at all then the following is correct:

but1.Text = ""

We’ve basically said the text that is to go inside the “Text” property of the “but1” object is to be…well nothing! What’s between those quotes is nothing so that’s what will go inside the Text property. Perfect!

So why don’t you go ahead and fix the errors, you should also be able to update the instruction label to have our initial message as well.

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>