Simplicty and flexibility!


Use of FixedWidth()


Started by Bill Nicholson
Search
You will need to Sign In to be able to add or comment on the forum!

Use of FixedWidth()

Hi,

I am trying to create tabulated output for use in an HTML memo field.  FixedWidth() seemed to be the solution but it pads the text with spaces which are ignored in HTML which looks for &nbsp instead. Is there are a way around this?

Thanks, Bill


Written by Bill Nicholson 20/12/14 at 17:23:36 Dataease [{8}]FIVE

Re:Use of FixedWidth()

I have more or less answered my own question by use of the new function StringReplace() which I hadn't noticed before. It isn't however as simple as might be hoped.

The first problem is that to replace a hard space with   means that we are using up 6 characters, and we soon run out of room if restricted to 255 characters. In practice we have to break the line down into little pieces.

The second problem is that we must change to a fixed width typeface to get tabulated output.  The resulting coding is as follows (NB we write the output to a text file which is read in later):

-- The next statement doesn't give tabulated output but is much simpler!
-- tempField1 := concat("<p>",Document No," ",Title," ",Revn," ", Purpose,"</p>") .
tempField1 := concat("<p><span style=/'font-family:courier new,courier,monospace/'> ",FixedWidth(Document No,0,20)," ") .
tempField1 := StringReplace(tempField1," ","&nbsp;") .
tempField2 := concat(FixedWidth(Title,0,40)," ") .
tempField2 := StringReplace(tempField2," ","&nbsp;") .
tempField3 := concat(FixedWidth(Revn,0,4)," " ,FixedWidth(Purpose,0,20),"</span></p>",chr(13)) .
tempField3 := StringReplace(tempField3," ","&nbsp;") .
retval := TextOut(concat(GetCurrent("AppPath"),"\field2.txt" ),tempField1 ) .
retval := TextOut(concat(GetCurrent("AppPath"),"\field2.txt" ),tempField2 ) .
retval := TextOut(concat(GetCurrent("AppPath"),"\field2.txt" ),tempField3 ) .

A sample line from the output file is:

<p><span&nbsp;style="font-family:courier&nbsp;new,courier,monospace">&nbsp;009_EPC_EXHIBIT&nbsp;IX&nbsp;&nbsp;&nbsp;DIRECTIVES&nbsp;OF&nbsp;HEALTH&nbsp;SAFETY&nbsp;AND&nbsp;ENVIRONM&nbsp;3&nbsp;&nbsp;&nbsp;&nbsp;</span></p>

The only slight niggle is that when this is read back using MemoReadFromFile() the typeface specification is ignored (see below) for some reason.  This is easily corrected by manual formatting of the final document although it isn't quite as intended.

<p>&nbsp;009_EPC_EXHIBIT&nbsp;IX&nbsp;&nbsp;&nbsp;DIRECTIVES&nbsp;OF&nbsp;HEALTH&nbsp;SAFETY&nbsp;AND&nbsp;ENVIRONM&nbsp;3&nbsp;&nbsp;&nbsp;&nbsp;</p>

The whole procedure is quite as complicated as the old formatting statements in Fortran from decades ago!

Bill


Written by Bill Nicholson 21/12/14 at 08:24:51 Dataease [{8}]FIVE

Re:Use of FixedWidth()

First question here is why do you want to use it in a HTML field when it formatted as a text field? Why not just create it as a text field and view it in a normal Memo field?


Written by DataEase 21/12/14 at 14:41:37 Dataease [{8}]FIVE

Re:Re:Use of FixedWidth()

First things first...

<p>&nbsp;009_EPC_EXHIBIT&nbsp;IX&nbsp;&nbsp;&nbsp;DIRECTIVES&nbsp;OF&nbsp;HEALTH&nbsp;SAFETY&nbsp;AND&nbsp;ENVIRONM&nbsp;3&nbsp;&nbsp;&nbsp;&nbsp;</p>

You problem here is simply that you mix up code and "text". This is not a DataEase problem but a HTML/Browser interpretation problem. When you convert spaces in code to &nbsp you basically "mess up" your code. In Code you need to use normal space as it is code, and in text is where you need to use &nbsp to get escpaed spaces.

<p>

<span style="font-family:courier;new,courier,monospace">

&nbsp;009_EPC_EXHIBIT&nbsp;IX&nbsp;&nbsp;&nbsp;DIRECTIVES&nbsp;OF&nbsp;HEALTH&nbsp;SAFETY&nbsp;AND&nbsp;ENVIRONM&nbsp;3&nbsp;&nbsp;&nbsp;&nbsp;

</span>

</p>



Written by DataEase 21/12/14 at 14:41:59 Dataease [{8}]FIVE

Re:Re:Use of FixedWidth()

Download Sample

Hi Bill.

You get 10 for the attempt and 1 for style!

I think this need a little "tough love" ;-)

The worst approach you can have to HTML it to treat it as a text file with fixed positions. Just forget about it and start over.

If you are to work with HTML just do it properly from the start and you save yourself a lot of grief later.

This is simple HTML and the only thing we use is a Table. http://www.w3schools.com/html/html_tables.asp

The attached sample is "stupid" but it showcase a best practice technique.

1. Use Templates for the HTML so you can easily adjust and edit it without changing your code.
2. Here we use string (255), but we would normally work directly with Memos and use MemoReplace etc.
3. In this sample we use labels for both Templates and Code so it is all visible directly in the sample, in the real world you would use tables/memos for the code and templates.

What we do in this sample is to build the HTML file by first copying the header (we could do manipulation in that too), then we add row for row of the table, and then we add the footer to close off the table in this sample but it could include much more HTML.

We have kept this sample as simple as possible to showcase the methodology, but feel free to expand on it.



The green and red texts are labels named Header, BodyLines and Footer that we access directly in the DQL script with GetLabelText() beware that GetLabelText() is a normal PRISM string function that will only return 255 characters even though Label can be 4000 characters long.

We use LabelExecDQL() execute the script in MyDQL label.

To preview the HTML file we simply use a simple text HTML field with derivation: concat(getcurrent("AppPath"),"\",FileName ).

We execute a RefreshForm() at the end of the script to get the HTML Field to refresh.

The HTML here is as simple as possible, you can of course use CSS styling of the elements but you can also use the "old fashioned" i.e not supported in HTML5 direct styling of the table like Width="100px" or width="10%" etc.

Have a go.






Written by DataEase 21/12/14 at 16:20:51 Dataease [{8}]FIVE

Re:Re:Re:Use of FixedWidth()

OK I will look at your example with interest. I wanted to avoid tables (with which I am indeed familiar) because the number of lines of tabulated data is variable and I didn't see an easy way to achieve this using a table. Maybe your example will help me.

I take your point about mixing the two types blank spaces (code and formatting) and freely admit that I am not an HTML expert.

Thanks Bill


Written by Bill Nicholson 21/12/14 at 16:57:32 Dataease [{8}]FIVE

Re:Re:Re:Re:Use of FixedWidth()

You can build the table completely dynamically so that shouldn't be a problem.

You can even add rows and span rows etc.

HTML is fantastic when you get under its skin. We will follow up with a lot of samples/templates on how to use HTML in combination with DE8 in the following months.

HTML and text in a way is like DE8/DG3 and DFD. Same roots, but you are better off starting as far away from the commonalities than the focus on them.

If you build in layers, styling and templates you will have a more flexible solution much faster.


Written by DataEase 21/12/14 at 18:18:00 Dataease [{8}]FIVE
DG3_ForumList