Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Formatting Computed Field

Status
Not open for further replies.

Statey603

Programmer
Nov 10, 2009
196
US
I have added a computed field to a data window to display a count of a specific field.

If I just add the count, it properly displays the count value. If I add text to precede the count, nothing shows up when I run it.

--------------------------------------------------------
WORKS:
count(client_service_tbl_auth_nbr for all)
--------------------------------------------------------
DOES NOT WORK:
"count: " + count(client_service_tbl_auth_nbr for all)
--------------------------------------------------------

What am I doing wrong?

 
Try:

"count: " + string(count(client_service_tbl_auth_nbr for all))

Matt

"Nature forges everything on the anvil of time
 
thanks !!! that works great.

Follow-up question:

Any idea why the call to string() is not required for all?
For example: if no text is included:
count(client_service_tbl_auth_nbr for all))

Or.....is this rule documented anywhere?

Thanks.
 
hello,

the problem is that you can't mix types in a computed column.

In your 'problem' situation you were concatenating a string value 'Count: ' with a number value, returned by the count() function.

If you'd only write a string pb would use string as the type for the computed column. If you'd only use count() pb interprets a number datatype for the column.

regards,
Miguel L.
 
The reason I ask is that we have a number of Computed Fields in older pre-PowerBuilder 11 code that mix text and data fields with no errors.

For example: "Total = " + count(indiv_name)
This works fine as is.

It seems the only time we run into problems is when we edit an existing or create a new computed field which is why I was wondering about where this is documented.

Could this have been changed in PB 11?
Does anyone know where this might be documented for computed field ?
 
yes you're absolutely right: using pb 10.0 it works without problems.

The (previous) automatic conversion when concatenating, is / was an 'undocumented feature', something that Sybase will never give you any garantees on. You might try to get information directly from Sybase, but documentation I don't think there'll be any.

The functionality seems to have been changed since version pb 10.5 (maybe also 10.2 ?) as you can read here:


(expand the first post of Shridhar Kumar):
--------------
6. Datawindow Compute Columns - Change in the undocumented feature: In the
Datawindow painter, when you paste a computed column for 'Page n of nnn' the
expression that you will get is: "'Page ' + page() + ' of ' +
pageCount()" even in PB 10.5. Notice how the string is seamlessly added to
the long returns of page() and pagecount() without a String() cast around
the two. Well, I had used this undocumented feature in other
computed columns. With PB10.5 some of these computed columns started failing
(without any error if you clicked the Verify button in their expression
dialog). In the runtime, on many of our reports, we started having blank
space in the summary area where, for example, we had a computed column with
expression:
'Total Patients: ' + Count (patient_num for all)


Solution: I had to comb through all of our reports and put a String () cast
around number value functions. For example, the expression for the above
computed column was changed to: 'Total Patients: ' + String (Count
(patient_num for all))


The frustrating thing is the page() computed column pasted in the dw painter
still works without a string cast. There is something wrong in how the
PB10.5 has been coded to yield this erratic behavior.





regards,
Miguel L.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top