REQUEST A DEMO

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.

 

ui_editor_form

 

Add a new ActiveX control to the form. In this case, it’s the Microsoft Forms 2.0 TextBox.

 

insert_activex

 

Next, set the properties on the textbox.

 

Notice the we’ve set:

  • Font: Courier
  • Locked: Yes
  • Scroll Bars: Both
  • MultiLine: Yes

 

 

 

 

ui_editor_property

Add a bit of ClearBasic code:

 

Sub Form_Load()
Me.DoDefault
lbl_switch.Tag = “system”
End Sub

Sub lbl_switch_click()
If lbl_switch.Tag = “system” Then
mstextbox.Value = txtBody.Text
mstextbox.Font.Name = “Courier”
txtBody.Visible = False
lbl_switch.Caption = “Display Message Text in the System Font”
lbl_switch.Tag = “fixed_width”
Else
txtBody.Visible = True
lbl_switch.Caption = “Text not formatted properly? Click here to switch to a fixed width font.”
lbl_switch.Tag = “system”
End If
End Sub

 

 

 

And now our form renders like so:

communication

and clicking the link changes the form to:

 

communication_fixed_width

 

 

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)”
OKButton 450,10,40,14
TextBox 10,10,400,400,.Textbox1,1 Or &H8000,”Courier”
End Dialog

Sub DisplayTextDialog(textToDisplay As String)
Dim textDialog As TextBoxDialog
textDialog.TextBox1=textToDisplay
Dialog textDialog,-1,0
End Sub

Sub lbl_dialog_click()
DisplayTextDialog txtBody.Text
End Sub

 

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:

 

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.