Crystal Reports running total on value returned from a formula - formula

I have a formula that extracts a value from a DB xml field and displays it in the details of my report. I'm trying to do a count on the various answers, but my global variables are not available to the running total setup, and neither is the Action Taken values on the report.
Is there a way to get the global variables into a running total, or am I going about this wrong?
The formula is as follows:
stringvar array x := split({msgMessages.XmlMessage},"</");
numbervar i := 0;
numbervar j := ubound(x);
stringvar array y := "";
numbervar k := 0;
global numbervar SA;
global numbervar RA;
global numbervar CA;
global numbervar VA;
global numbervar TC;
global numbervar PWCB;
global numbervar CCWO;
for i := 1 to j do(
if instr(x[i], "<ACTIONTAKEN>") <> 0 then(
k := k + 1;
redim preserve y[j];
y[k] := extractstring(x[i],"<ACTIONTAKEN>","</ACTIONTAKEN>"))[i]);
whileprintingrecords;
stringvar array y;
select y[1]
case "Scheduled Appointment" : SA = SA + 1
case "Rescheduled Appointment" : RA = RA + 1
case "Cancelled Appointment" : CA = CA + 1
case "Verified Appointment" : VA = VA + 1
case "Transferred Call" : TC = TC + 1
case "Patient Will Call Back" : PWCB = PWCB + 1
default: CCWO = CCWO + 1;
y[1]

Change
whileprintingrecords;
to
whilereadingrecords;

Related

Why inside Let while loop does not work SML

i am new at Standard ML and i have a question , at the code below when
i run without the let-in structure , the code runs and gives result .When i put the the let-in
it shows syntax errors . Can anyone help me ?
fun findInd([],size, value , ans , l , h ) = ~1
| findInd(lista ,size, value , ans , l , h) =
let
val midval = Real.round((real l + real h) / real 2)
val Nelem = List.nth(lista,midval)
in
if l<=h then
if Nelem <= value then findInd(lista,size,value,midval,midval+1,h )
else findInd(lista,size,value,ans,l,midval+(~1) )
else
ans
end;
let (* <-- this let gives the problem *)
val s = 0
val sum = ref s
val maxlen = 0
val maxlenptr = ref maxlen
val counter_start = 0
val counter = ref counter_start
val arr = [1,5,~58,~1]
val presum = [~53,~52,1,6]
val minInd = [3,2,0,0
while !counter < List.length(arr) do (
sum := !sum + List.nth(arr,!counter);
if !sum >=0 then maxlenptr := !counter + 1
else
let
val ind = findInd(presum, List.length(arr) , s , ~1 ,0 , List.length(arr) + (~1) )
val temp = List.nth(minInd,ind)
in
if ind <> ~1 andalso temp < counter_start then maxlenptr := Int.max(!maxlenptr,counter_start + (~temp))
else ()
end;
counter := !counter + 1
);
val m = !maxlenptr
in (* <--- this in *)
m
end;
The syntax of let is let <declarations> in <expression> and a while loop is not a declaration. You'll need to move it after the in (like you did with the ifs in the other lets).

How to define a constraint for one bit random variable?

In my case,
If the value of a bit is "1" then my constraint will have a higher weight for '1', if the bit is "0" then my constraint will have higher weight for '0'. How to constraint it?
I get a syntax error for this piece code
rand bit value;
bit x; // Has either 1 or 0 depending on external signal
constraint constraint_c { value dist { x := 3, ~x := 1};};
Please help me on this. Thank you :)
You can put an if-else in a constraint
rand bit value;
bit x;
constraint c {
if(x)
value dist {1 := 3, 0 := 1};
else
value dist {1 := 1, 0 := 3};
}
Your weights can also be variables
int weight0, weight1;
constraint c {
value dist {1 := weight1, 0 := weight0};
// set before calling randomize
if (x) begin
weight1 = 3; weight0 =1;
end else begin
weight1 = 1; weight0 =3;
end
Or expressions
constraint c {
value dist {1 := x?3:1, 0 := x?1:3};

How to solve this errors of plsql?

its show this type of error help me to solve it i attch screen shot hereenter code here
declare
empnos NUMBER(9,2);
L NUMBER(9,2);
ANS NUMBER(9,2);
function avg_sal(x number, y number) return number AS
begin
ANS := (x / y) * 100;
return ANS;
end avg_sal;
BEGIN
empnos := :EMPNOr;
select TOTAT_SAL,NOOFEMP from dept
where DEPTNO=(
select deptno from emp
where empnos=emp.empno
);
L := avg_sal(TOTAT_SAL,NOOFEMP);
END;
As error shows and sticky bit above mentioned, you need to take result into variables:
Here is an example:
declare
empnos NUMBER(9, 2);
L NUMBER(9, 2);
ANS NUMBER(9, 2);
v_total_sal NUMBER(9, 2);
v_nooofemp NUMBER(9, 2);
function avg_sal(x number, y number)
return number AS
begin
ANS := (x / y) * 100;
return ANS;
end avg_sal;
BEGIN
empnos := :EMPNOr;
select
TOTAT_SAL,
NOOFEMP
into v_total_sal,
v_nooofemp
from dept
where DEPTNO = (
select deptno
from emp
where empnos = emp.empno
);
L := avg_sal(v_total_sal, v_nooofemp);
END;

How can I write this algorithm using iteration?

How can I write this algorithm using iteration?
function generate(num1:byval)
if num1 > 10 then
return 10
else
return num1 + (generate(num1 + 1) DIV 2)
endif
endfunction
So it's not straight forward so I start by doing some grunt work:
n result
11.. 10
10 10
9 9 + 10/2
8 8 + (9 + 10/2)/2
7 7 + (8 + (9 + 10/2)/2)/2
This looks like a pattern.. While the recursive version started on the input and went upwards it's easy to see that by starting at 10 and going downwards one can simply update the accumulator by halving the value and adding the current value.
This can easily be implemented using a helper:
procedure generate(num : integer) : integer
begin
generate := generateHelper(10, num, 0)
end
procedure generateHelper(cur : integer, num: integer, acc : integer) : integer
begin
if cur = num then
generateHelper := cur + acc/2;
else
generateHelper := generateHelper(cur - 1, num, acc/2 + cur);
end
Or by using a loop:
procedure generate(num : integer) : integer
var cur, acc : integer;
begin
for cur := 10 downto cur do
acc := acc / 2 + cur;
generate := acc;
end
If you work out some values for the function…
f(10) = 10
f(9) = 9+f(10)/2 = 9+10/2 = 14
f(8) = 8+f(9)/2 = 8+14/2 = 15
…
You will get a sense that you could repeatedly apply the same formula to a value in a loop. You see if you start from 10, you divide by 2 and add 9, then divide by 2 and add 8, and keep going until you reach the number given to the function. That would look something like this, e.g. in JavaScript:
function generate(n) {
let x = 10;
for(let i = 10; i > n; i--) {
x = i - 1 + x / 2;
}
return x;
}

Pascal error: illegal qualifier

The code below is supposed to create a 3x4 matrix and and print the sum of all numbers each row. However, upon compiling it, I keep getting the following errors:
jdoodle.pas(26,25) Error: Illegal qualifier
jdoodle.pas(33,32) Error: Illegal qualifier
jdoodle.pas(41,32) Error: Illegal qualifier
jdoodle.pas(48,24) Error: Illegal qualifier
jdoodle.pas(56,4) Fatal: There were 4 errors compiling module, stopping
Fatal: Compilation aborted.
The lines in question are:
line 26: readln (A[i, j]);
line 33: B[i] := B[i] + A[i, j]
line 41: C[J] := C [J] + A[i,j]
line 48: write (A[i, j]:5);
Could anyone clarify this for me please? The main problem is, that I don't really know what that error code means. I have noticed that 'A[i,j]' is in all lines that are mentioned in the errors, but I just can't find out what is wrong with it.Any help would be greatly appreciated!
And here is my complete code:
Program Matrix (input, output);
const
ZEILENMAX = 3;
SPALTENMAX = 4;
type
tZeile = 1..ZEILENMAX;
tSpalte = 1..SPALTENMAX;
tMatrix = array[tZeile] of integer;
tZeilensumme = array [tZeile] of integer;
tSpaltensumme = array [tSpalte] of integer;
var
A : tMatrix;
B : tZeilensumme;
C : tSpaltensumme;
i : tZeile;
j : tSpalte;
begin
for i := 1 to ZEILENMAX do
for j := 1 to SPALTENMAX do
readln (A[i, j]);
for i := 1 to ZEILENMAX do
begin
B[i] := 0;
for j := 1 to SPALTENMAX do
B[i] := B[i] + A[i, j]
end;
for j := 1 to SPALTENMAX do
begin
C[j] := 0;
for i := 1 to Zeilenmax do
C[J] := C [J] + A[i,j]
end;
writeln;
for i := 1 to ZEILENMAX do
begin
for j := 1 to SPALTENMAX do
write (A[i, j]:5);
writeln (B[i]:10)
end;
writeln;
for j:= 1 to SPALTENMAX do
write (C[j]:5);
writeln
end.
Let us transcript the following piece of code:
const
ZEILENMAX = 3;
type
tZeile = 1..ZEILENMAX;
tMatrix = array[tZeile] of integer;
var
A : tMatrix;
it is equal to:
type
tZeile = 1..3;
tMatrix = array[tZeile] of integer;
var
A : tMatrix;
and this is similar to:
type
tMatrix = array[1..3] of integer;
var
A : tMatrix;
Members of array A can be accessed by a single index:
A[1] := 0; but not A[1,1] := 1 or alike.

Resources