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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Using a function with with sub totals on report

Status
Not open for further replies.

DarrenWard

IS-IT--Management
Feb 15, 2002
217
0
0
GB
I have a function that turns seconds into a time string.
ie. you put in 12365 and get out "03:26:05"

I use it in a report and it works fine on the Detail of the report, but when I use it on the sum in the Group Footer, I just get three stars print out.

Is there a problem with using a finction on a calculated field?

Darren

GuiltyMaggot - The best rock band in the world!
 
DarrenWard

Stars sometime indicate that the textbox is not wide enough to display the value, try stretching.

Mike Gagnon

If you want to get the best response to a question, please check out FAQ184-2483 first.
 
Cheers Mike,

I thats pretty much what I thought at first but making the field on the report as large as you like makes no difference, I still just get the same about of stars.

If I just have the sum of the field it print the value fine, but if I put SecondsToTime(_TimeTaken) as a summed field in the Group Footer I get the problem.

FUNCTION SecondsToTime (_Seconds)
_S = ":" + RIGHT("0" + ALLTRIM(STR(MOD(_Seconds, 60))), 2)
_M = ":" + RIGHT("0" + ALLTRIM(STR(MOD(INT(_Seconds/60), 60))), 2)
_H = RIGHT("0" + ALLTRIM(STR(INT(_Seconds / 3600))), 2)
RETURN _H + _M + _S

Darren

GuiltyMaggot - The best rock band in the world!
 
Darren

I'm not seeing this behavior. I used:

Code:
PUBLIC myVar 
myVar = secondstotime(12345)

FUNCTION SecondsToTime (_Seconds)
 _S = ":" + RIGHT("0" + ALLTRIM(STR(MOD(_Seconds, 60))), 2)
 _M = ":" + RIGHT("0" + ALLTRIM(STR(MOD(INT(_Seconds/60), 60))), 2)
 _H = RIGHT("0" + ALLTRIM(STR(INT(_Seconds / 3600))), 2)
  RETURN _H + _M + _S

And I put a textbox on a report with myVar as the source and I can preview the report, and it show the value.

Mike Gagnon

If you want to get the best response to a question, please check out FAQ184-2483 first.
 
Mike,

Thank you for your help so far, can you do me a favour;

CREATE CURSOR _temp(name c(1), number n(5))
SELECT _temp
APPEND BLANK
REPLACE name WITH "A", number WITH 12345
APPEND BLANK
REPLACE name WITH "A", number WITH 23456
APPEND BLANK
REPLACE name WITH "B", number WITH 34567
APPEND BLANK
REPLACE name WITH "B", number WITH 45678

REPORT FORM c:\report PREVIEW NOCONSOLE

FUNCTION SecondsToTime (_Seconds)
_S = ":" + RIGHT("0" + ALLTRIM(STR(MOD(_Seconds, 60))), 2)
_M = ":" + RIGHT("0" + ALLTRIM(STR(MOD(INT(_Seconds/60), 60))), 2)
_H = RIGHT("0" + ALLTRIM(STR(INT(_Seconds / 3600))), 2)
RETURN _H + _M + _S

The report should have a data grouping for name, place the same text box in the group footer and get the report to sum on it.

Darren

GuiltyMaggot - The best rock band in the world!
 


What? You to sum the name field?

The report should have a data grouping for name, place the same text box in the group footer

Mike Gagnon

If you want to get the best response to a question, please check out FAQ184-2483 first.
 
DarrenWard,

You'll need to create a report variable in order to sum the total seconds and display it formatted by your function. You can't sum on a function that returns a character string. I'm guessing at what you are asking here, since I am a little confused as to what you want as Mike is given what you have said. However, there is no way that summing the "number" field is giving you problems, so what I figure you are doing is trying to sum on your function...I am suprised however that it only shows you stars and doesn't throw an error if this is what you are doing. In any event I think a report variable to hold the seconds will allow you to solve this.

Slighthaze = NULL
[sub]craig1442@mchsi.com[/sub][sup]
"Whom computers would destroy, they must first drive mad." - Anon​
[/sup]
 
Just to clarify, the report is grouped on the 'name' field with a sub total summing the 'number' field with the function wrapped around it.

I assumed that the number would be totaled and then have the function applied to it, but it appears that it works the other way around.

Darren

GuiltyMaggot - The best rock band in the world!
 
I set up a variable within the report (something id not used or concidered before) and now its working fine.

Thank you both.

Darren.

GuiltyMaggot - The best rock band in the world!
 
Darren,
Glad to hear you got it sorted out and that the variable idea worked for you.

Slighthaze = NULL
[sub]craig1442@mchsi.com[/sub][sup]
"Whom computers would destroy, they must first drive mad." - Anon​
[/sup]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top