Nevertheless this can be done in other parts in the code, namely the Parse function which I will cover later in this tutorial. Here it becomes apparent, that Masked Text Boxes are primarily made for strings of a fixed length. Though it is possible to use the mask symbol “9″ to denote an optional digit we will run into troubles when formatting a string with a minus sign at the first location (where we used the mask symbol “#”).
The choice to include literals is a purely cosmetic one, cosmetic as in “it will still influence how to implement our Parse function, but that doesnt matter much”.
It pretty much only determines what means we have to use to manipulate the formatted string to get us our values.
Those three ’0′s tell the mask to accept three (required) digital numbers.
The next mask symbol is a “°” which does not denote anything and therefore is used as literal, that is it appears as itself.
Text string, if it is not included it will get converted into spaces.
I chose to include the Prompt character in the string as when we need to determine weather the entered longitude is valid we do have to check weather all numbers have been filled in.
As this struct represents a latitude, you need three fields (degrees (°), minutes (‘) and seconds (“)).
Also we need a constructor that passes those three values. It is primarily used by the Form Design Manager to autogenerate code, which is not quite that useful to us as we wont be using this feature as we are creating our own, inherited class, but it can’t hurt to provide the mentioned functionality either.
Some people might have noted, that there is no explicit error checking done, i.e.
the minutes and seconds values are not supposed to be greater than 60. The groovie thing about doing it this way is, that all our error checking and initialization, etc. This is easier to debug and a lot cleaner, especially if this is to be part of a bigger project.
If you ever need another representation of the string you can always provide a function which does just that.