View Full Version : Funky error on calc field


Howard G. Cornett
08-17-2004, 02:27 PM
See the attached message. I get it when I try to create this calculated field:

bar = = ""img SRC=\"c:/TEAM/redstripe.gif\" ALT=\"_________\" WIDTH=\""+ alltrim(str(Rating/maximum(Rating)*400))+"\" HEIGHT=\"5\" BORDER=\"0\" ""

I plan on using it to display a bar graph using HTML. It is meant to be only a character field. When I enter it in the expression builder it shows it is OK but does not display the last part starting at border (see second attachment). When I try to save it, I get the error I mentioned at the beginning.

At first I thought maybe it was because I started the component in the beta, but I get the same error when I create a new component as well.

Thanks in advance for any help.


Selwyn Rabins
08-17-2004, 05:27 PM
it looks like there is a pretty stupid error in the grid component. i have fixed it. in the mean time the work around is easy.

the problem is that you can't use = signs in the expression for a calculated field. the work around is to use chr(61) which is the same as =

so, instead of "src=image.jpg" you would write :

"src" + chr(61) + "image.jpg".

the fix allowing = signs in calc fields will be in next patch.

very sorry about this.

Howard G. Cornett
08-17-2004, 06:10 PM

Thanks for the fix, but I still get the error. And the result in the expression builder still stops at height = "5". Any ideas why?


Selwyn Rabins
08-17-2004, 07:34 PM
New Page 1

The expression that you said you were trying to use is:
""img SRC=\"c:/TEAM/redstripe.gif\" ALT=\"_________\"
WIDTH=\""+ alltrim(str(Rating/maximum(Rating)*400))+"\" HEIGHT=\"5\"
BORDER=\"0\" ""
This cannot work because it contains errors. This part of the above
expression is wrong: alltrim(str(Rating/maximum(Rating)*400))

You need to fix this. I would help, but I don't know what you are trying
to do here. You can tell it is wrong by testing it in the Interactive window
(after first creating a variable called 'Rating' and assigning a test value to
the variable).

If you replace the part of your expression that is wrong with a temporary
'placeholder' ("ratingsubexpression"), and replace the = signs with chr(61),
then you get the correct expression that you need to enter in the grid:
""img SRC"+chr(61)+"\"c:/TEAM/redstripe.gif\" ALT"+chr(61)+"\"_________\"
WIDTH"+chr(61)+"\""+ "ratingsubexpression"+"\" HEIGHT"+chr(61)+"\"5\"
BORDER=\"0\" ""
If you were to test the above expression in the Interactive window, you
would get:
"img SRC="c:/TEAM/redstripe.gif" ALT="_________" WIDTH="ratingsubexpression"

Howard G. Cornett
08-17-2004, 09:49 PM
I've almost got it now. The only problem is that if I display it as an image, it does not allow me to change the width based on the calculated field. As a result, I used control type label but that also doesn't work. I think it may be because the HTML escape characters are substituted so that the page displays the text rather than rendering the image. Here is the text from the HTML window

"img SRC="c:/a5webroot/CoreCapital/default/redstripe.jpg" ALT="_________" WIDTH="271.429" HEIGHT="5" BORDER="0""

Howard G. Cornett
08-17-2004, 09:50 PM
I've almost got it now. The only problem is that if I display it as an image, it does not allow me to change the width based on the calculated field. As a result, I used control type label but that also doesn't work. I think it may be because the HTML escape characters are substituted so that the page displays the text rather than rendering the image. Here is the text from the HTML window

"td class="EncyclopaediaDataTD""AAUK "/td"
"td class="EncyclopaediaDataTD""11/01/2002 "/td"
"td class="EncyclopaediaDataTD"""DIV style="text-align: right;""5 "/DIV""/td"
"td class="EncyclopaediaDataTD"""DIV style="text-align: right;""75 "/DIV""/td"
"td class="EncyclopaediaDataTD"""DIV style="text-align: right;""4 "/DIV""/td"
"td class="EncyclopaediaDataTD"""DIV style="text-align: right;""76 "/DIV""/td"
"td class="EncyclopaediaDataTD""<img SRC="c:/a5webroot/CoreCapital/default/redstripe.jpg" ALT="_________" WIDTH="271.429" HEIGHT="5" BORDER="0"> "/td"

Selwyn Rabins
08-18-2004, 05:26 AM
if you choose label, then a5 will htmlencode the data. that's NOT what you want.

you have to choose image because that's what it is.

what do you mean by this: "it does not allow me to change the width based on the calculated field"

are you trying to control the display width of the column?

if so, then this is easily done using inline styles. for example if you set the 'cell in-line style' for the image column to :

width: 3in;

then that will set the column width to 3 in. you can use the pop up style builder for the inline style. the width property is on the 'position' tab of the style editor.

Howard G. Cornett
08-18-2004, 05:44 AM
I have tried to set the width as you described using an A5 expression, but it doesn't seem to work. How can I change the width based on the value in the current record? What I have tried ends up looking like this:

"td class="EncyclopaediaAltDataTD""AAPL "/td"
"td class="EncyclopaediaAltDataTD""11/01/2002 "/td"
"td class="EncyclopaediaAltDataTD"""DIV style="text-align: right;""5 "/DIV""/td"
"td class="EncyclopaediaAltDataTD"""DIV style="text-align: right;""59 "/DIV""/td"
"td class="EncyclopaediaAltDataTD"""DIV style="text-align: right;""4 "/DIV""/td"
"td class="EncyclopaediaAltDataTD"""DIV style="text-align: right;""60 "/DIV""/td"
"td class="EncyclopaediaAltDataTD"""img style="height: 5px; width: "%a5 Rating/maximum(ratings-"Ratings)*400%"px;" src="C:\Team\Corecapital.WebProjects\Default.WebProject\redstripe.jpg" alt=""" "/td"

It doesn't work because it never resolves the formula into a number for the width. Perhaps the formula in incorrect? I am trying to calculate the fraction of the largest value the current record is. I want to take the current Rating (a field value) and divide it by the maximum value that Rating has in the table. Then I want to multiply the result by 400. Finally, I want the width of the image displayed to match the result of this calculation. Am I doing it wrong? Is there a better way?


Selwyn Rabins
08-19-2004, 05:50 AM
New Page 2

this is not legal:

"%a5 Rating/maximum(ratings-"Ratings)*400%"

you can escape to xbasic in the property definition.
you can achieve the same effect by setting the value for this property in
if you edit the page that contains the component, you will see in the "Head"
section of the page there is xbasic code that loads the component. a pointer
variable is assigned when the component is loaded.
immediately after the command the loads the component is a
with varname
end with
sequence. Inside this with...end with you can set any of the component

Selwyn Rabins
08-19-2004, 05:51 AM
i meant to say "you can not escape to xbasic in the property definition"

Howard G. Cornett
08-19-2004, 06:22 AM
Thanks, Selwyn! What are the component properties and how exactly do I set them to change the formatting for image (the width, that is)?


Selwyn Rabins
08-20-2004, 04:32 AM
when you place a component on a page there is a prompt "override any of the component settings".

after you place the component on the page, if you switch to source view you will see something like this:

tmpl_invitems = a5w_load_component("invitems")
with tmpl_invitems
with field_info[2]
Column.InLineStyle = "width: .5in;"
end with
componentName = "invitems"
end with

the section of code between:
with "tmpl_invitems" and the second "end with" is where properties of the component can be set at run time.

Selwyn Rabins
08-20-2004, 10:28 AM
Ok, Howard, I think I finally get it.
You want a grid the HTML in one of the columns looks something like this:

"img src="graph.jpg" with="1in">

"img src="graph.jpg" width="1.5in">

"img src="graph.jpg" width="1.75in">

"img src="graph.jpg" width="3in">

While this would be extremely easy to do if you were generating the HTML
using your own Xbasic script, you want to do it as part of a Grid component
because you want to take advantage of everything else that the Grid component
offers (syle sheets, paging, search, sorting etc.).
Unfortunately, I can't think of any way to actually achieve this with the
Grid component. The technique I described in an earlier message about overriding
the Grid component's properties does not apply to your problem because you want
to change a property on every row of the Grid - not for the Grid as a whole.
I have come up with a more generic solution which I will add in a future
patch. I will create a new control type called "Template". Currently, a field
can be an "image", "label", "textbox" etc. However, if a field's type is set to
'template', then you can define your own html for that column.
In the template, you will be able to refer to values from other columns in
the Grid. So, in your case, say you have a column in the Grid called 'rating'
and you want the width attribute to be based on this value, your template for
column would be:

"img src="graph.jpg" width="{rating}" >
I am not sure when I will get this done by, but I will definitely do it
because it is an extremely powerful feature that will dramatically extend the
power of the Grid component.

Howard G. Cornett
08-20-2004, 10:46 AM
You got it exactly, Selwyn! Thanks!


Lenny Forziati
10-15-2004, 07:43 AM
Howard, all you need to do is define a calculated field in your grid, then use this calc field for the width part of a freeform layout. Tha attached database has a smal sample of how to do this.