Day 003 - More entry fields and some easy code refactoring

One niggling thing I've noticed over the past couple of sessions: I have some unresolved GUI warnings:

The second subject, anchoring, doesn't come up until page 208 in the tutorial. And as it's just a warning I'll ignore it for now. 

The first one is easy enough to fix. In the window properties I just set a value for the Title (in Clarion this is called the caption):

Just for fun I added a second language.

On returning to the window I still only saw an entry for English, but after I closed and reopened the window I saw the second language entry, which defaulted to whatever value I'd set for the first one. 

I'd be interested to know if there are any other (and possibly more efficient) ways to supply translations when supporting multiple languages. 

Now, where was I? Ah, page 41 of the tutorial, which mentions pressing F1 for context sensitive help. Okay, that works. And the help mentions the use of the CR constant to add a carriage return (line break) to a message statement:

"line 1" + CR + "line 2"

The next section of the tutorial starts with adding a splitter control, and points out another way to add controls: using the Insert | Control menu selection.

This brings up the splitter wizard:

Note that you can disable the wizard for future insertions. I just accepted the defaults, then with a bit of squinting located the splitter control on the window and dragged it to a suitable location. 

I then added a currency control, and followed the instructions to change the type to Currency + Euro:

In the Whenever Modified embed of one of the numeric fields I added the following code to update the 

When I ran the program I discovered that my entry field showed in dollars and my result field in Euros. What had I done wrong?

I needed to compare my settings for the two fields. I was pleasantly surprised to see that I could bring up two property windows at the same time, which showed me that I had not in fact set the properties the same way. 

Being in Canada, I can only guess that the reason for enforcing a Euro symbol would be for those European situations where a user might be dealing in Euro currency but not have the Euro as their computer's default currency. 

Next I followed the directions for adding a combo box to allow for entry of VAT values rather than a fixed value. Here's the combo box wizard:

I used the wizard to create a combo box with some preset VAT tax rates. And then I changed the code per the tutorial to calculate values based on the selected VAT rate.

EDT_PriceIOT = EDT_PriceBT * (1 + Val(COMBO_VAT..DisplayedValue)/100)

On running the window I noticed two things. One, the Price IOT value is updated on each keypress, not just when the field is accepted. And two, the Price IOT value is not updated when the VAT selection changes.

The tutorial makes not of this, and suggests that one way to deal with this is to copy and paste code. 

But whatever you do, don't stop reading at this point! Because the next bit explains a better way.

Refactoring code

Refactoring is the processing of reworking your code to improve its quality. In fact I hadn't bothered doing the copy and paste because I'd assumed I'd want to create a local procedure of some kind. WinDev makes this easy. Just highlight the code in question, right click, and choose Create a procedure | Create a local procedure containing the selected code. (You can also refactor the code as a global procedure.)

I created my procedure as CalculateVAT, which changed my code to:

I added the CalculateVAT() call to the Row Selection of COMBO_VAT embed and my Price IOT updated whenever I changed the price or the VAT. 

That took me up to page 46. More tomorrow...