Displaying text using a fixed width font in the Clarify Client
We received a request recently about how to deal with some text in the system that was formatted using a fixed width font.
For example, a customer might send in an email that contained some text that was laid out in a nicely formatted table structure. Such as this:
5.17637 |-----+-----+--------------+----------+--+-------+----------+-----+-----| | | JD00| firma ip | gumpendor| 1| Wien | Empfänger| fa. | 05.0| | | 0010| österreich | ferstr. | 0| | verzogen | nich| 8.20| | 5239| 4300| gmbh - | 19-21 | 6| | | t | 09| | 1478| 0140| | | 0| | | mehr| | | | 6959| | | | | | da!!| | | | 22 | | | | | | | | | | | | | | | | | | |-----+-----+--------------+----------+--+-------+----------+-----+-----|
But, when viewing it in the Clarify Classic Client, it looked like this:
5.17637
|—–+—–+————–+———-+–+——-+———-+—–+—–|
| | JD00| firma ip | gumpendor| 1| Wien | Empfänger| fa. | 05.0|
| | 0010| österreich | ferstr. | 0| | verzogen | nich| 8.20|
| 5239| 4300| gmbh – | 19-21 | 6| | | t | 09|
| 1478| 0140| | | 0| | | mehr| |
| | 6959| | | | | | da!!| |
| | 22 | | | | | | | |
| | | | | | | | | |
|—–+—–+————–+———-+–+——-+———-+—–+—–|
The reason is that by default, the Clarify Client does not use a fixed width font (where each character is given the same width, as by a typewriter)
If you changed the font used by Clarify to be a fixed width font (such as courier), then the text would look OK. But most users wouldn’t want to work with a fixed width font all day long within Clarify (I know I wouldn’t).
And because this situation is a rarity, we want to be able to handle it as an exceptional case, as opposed to the norm.
One solution: use a different text box control
The multi-line text box control within Clarify does not allow the font to be set independently (either at design time or at run time). Instead, we can use a different text box control that does allow for this. One example is the Microsoft Forms 2.0 Textbox.
The plan:
- Add a 2nd textbox to the form.
- Allow the user to click a link if the text isn’t rendering properly.
- This button will copy the contents of the default textbox into the new textbox.
- The new textbox will have its font set to a fixed width font
- Hide the baseline textbox
For this example, we’ll use the Communication form.
Design the form in UI Editor
We’ll add a new label that will “switch” the text boxes.
Add a new ActiveX control to the form. In this case, it’s the Microsoft Forms 2.0 TextBox.
Next, set the properties on the textbox.
Notice the we’ve set:
- Font: Courier
- Locked: Yes
- Scroll Bars: Both
- MultiLine: Yes
Add a bit of ClearBasic code:
Sub Form_Load() Me.DoDefault lbl_switch.Tag = “system” End Sub Sub lbl_switch_click() |
And now our form renders like so:
and clicking the link changes the form to:
An alternative solution: display the text in a dialog
Instead of swapping out text boxes, we can simply popup a new dialog window.
We’ll use the Dialog capabilities of BasicScript (the underlying scripting engine of ClelarBasic). Dialogs such as this are rarely used, but I’ve never had an with them.
The reason I chose a Dialog object is that you can set the font programmatically.
The ClearBasic code:
Sub Form_Load() Me.DoDefault End Sub Begin Dialog TextBoxDialog 20,20,500,420,”Text (in a fixed width font)” Sub DisplayTextDialog(textToDisplay As String) Sub lbl_dialog_click() |
Notice that we’ve set the font to Courier when defining the TextBox. Even though we set it at design time, I had to also set it at runtime to make it work.
Now clicking the link, will display a Dialog:
Fun with ASCII Art
While looking for some examples of formatted text, I stumbled into the wide world of ASCII art. wow. some people have a LOT of time on their hands. (BTW, check out the Google logo when you search for ascii art)
! /^\ / \ | | ( ) | | /^\ | /^\ \ / /^\ | /^\ |O| /^\ ( )|-----|( ) /^\ |O| |_| |-| |^-^|---||-----||---|^-^| |-| |_| |O| |O| |/^\|/^\|| | ||/^\|/^\| |O| |O| |-| |-| ||_|||_||| /^\ |||_|||_|| |-| |-| |O| |O| |/^\|/^\||( )||/^\|/^\| |O| |O| |-| |-| ||_|||_|||| ||||_|||_|| |-| |-| |O| |_|----|___|___|||___|||___|_|_| |O| |O| |_| |_| /_______________________________________\ __|_______________________________________|___|
Other Ideas?
Got some other ideas on how to solve this problem? Lets hear them! Leave a comment, or drop me an email.