Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

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

 

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

Image Added

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?

Image Added

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. 

Image Added

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:

Image Added

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.

Image Added

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.)

Image Added

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

Image Added

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...