How To Create Cumulative Variable in Crystal Reports 2008 - crystal-reports-2008

Maybe is a stupid question but i can`t find a example to:
CurrencyVar x;
if(x=0) then
x:= {saldo}+{CtaCte.Haber}-{CtaCte.Debe}
else
x:=x+{CtaCte.Haber}-{CtaCte.Debe}
Currently this calculated field fails. The varaible x always remains at zero

Seeking examples I had saved I found that to do this I must do as follows:
CurrencyVar x;
if(PreviousIswNull({CtaCte.Haber})) then
x:= {saldo}+{CtaCte.Haber}-{CtaCte.Debe}
else
x:=x+{CtaCte.Haber}-{CtaCte.Debe}
This works because the first record the previous value will always be null

Related

Returning the Maximum of Date1 and Date2 in Cognos 10.2

At my company we've recently moved from SSRS to a Cognos-based Reporting System, I don't have much experience with Cognos as a whole and am running into some issues that seem trivially easy to fix but I am struggling so far.
In our DB we segregate two kinds of contact date information [Date Emailed] and [Date Called], I'm attempting to combine both to get a [Date Contacted] field returned.
Is there a way for me in Cognos report builder to find the max of both of these data items?
I would have expected some kind of "c = MAX(a,b)" function like the below to be available but from what I've seen, apparently not.
[Date Contacted] = MAX([Date Emailed], [Date Called])
Also, we have no access to modify SQL or any Cognos related part except the Report Builder which makes this all the more fun.
I feel like the answer will be building a CASE statement to do this, but I'd rather stay away from CASE if I can.
Thanks,
Blu
I wonder if you could use _days_between to determine which is the newer date.
Something like this:
Case
(_days_between (X, Y) > 0 )
then (x)
// or Y; I can't remember whether the value returned is a negative or positive if the first parameter is greater than the second. The expression editor's help will say. Anyway, this is just to point you in a direction rather than me coming down from Mount Sinai.
case
(_days_between (X, Y) > 0 )
then
(x) // or Y;
Else (x or y but it doesn't matter as there's no difference )

incorrect string formatted as a percentage

Assume that numQuestions and numCorrect are variables that has been given values. Write a sequence of statements that assigns to the string percentIncorrect a string formatted as a percentage indicating the percentage of INCORRECT questions correct to two decimal places.
percentIncorrect = ((numQuestions - numCorrect) / numQuestions).ToString("p2")
I tried to do it as well but couldn't get the right answer I know you want a visual basic statement. This is what I have so far.
percentInCorrect = (numCorrect/numQuestions ).ToString("p")

Crystal Report displaying formula result as 00

First of all I would like to apologize if this has been asked before, I just couldn't find the answer.
To the point:
My problem is as follows: I am using Crystal Reports for VS2010 and I have a field that should dispaly 1 or -1 based on an If check
If IsNull ({Orders.OrderReplacedBy})
Then 1
Else -1
It should display in my report 1 for null values of the field and -1 otherwise. Problem is that in my report I get only .00 no matter the value of the if test.
Furthermore I have another formula field that does of a sum of all the 1s and -1s showed on the report, and it seems to be working a little weird. In my database I have 772 total rows, of which 39 are NULL (so there should be 733 1s and 39 -1s with a sum of 694) and the displayed sum is 488. The code for the sum is as follows:
Sum({#N})
where N is the field where I calculate the 1s and -1s.
What I've tried so far:
changed the If test from IsNull to ToText({Orders.OrderReplacedBy})=""
changed the If test to {Orders.OrderReplacedBy}>0 as the OrderReplacedBy field in the database is numeric and there cannot be values less than zero, so the NULLs should just trigger the Else.
trid to change the display of the formula to "1" and ToNumber("1") nothing seems to work
I honestly have no more ideas of what else to try and I also have no knowledge of Crystal Reports (I am only working with it for 2 days and just need to modify a report on an existing app).
Any help would be appreciated,
Thanks :)
P.S.: I am working with Silverlight 4
Since no one answered I presume that this hasn't happened to anyone or isn't of much interest. But after doing some more research and trying out other stuff I've found a workaroud that I'll post (maybe someone else bumps to this, who knows?):
In the N formula (I don't know why it didn't work the last time I tried) I changed things like this:
If IsNull({Orders.OrderReplacedBy})
Then "1"
Else "-1"
Added a new formula that isn't used on the report called Numbers
If {#N}="1"
Then 1
Else -1
And then I changed the sum formula to match the intermediate field
Sum({#Numbers})
I still don't know the reason why the report didn't want to show me the numbers in the N formula, nor why the sum formula didn't calculate the correct sum.
I hope this is at least going to be useful to someone else,
Cheers!

VHDL integer'image Returns "0"

Here is my dilemma:
I'm very new to programming in VHDL, and I'm currently working on an independent study project for a university class. I've made some descent headway, but I've run into an issue I haven't been able to solve.
What I'm trying to do is to display a "register" (or registers) on an LCD monitor and have it update periodically. For the time being, these values will always be integer numbers.
I have code written which displays numbers properly on the screen if that value is passed as a variable that is never altered or as a hard-coded value. However, I want to update a variable by adding to it, then pass that to my function and display it.
Essentially what I'm trying to do is this:
Every 'x' clock ticks, increment a register's value, pass that to my update_screen function which returns a new screen, and then display that further below. However, once I increment or change through reassignment (doesn't seem to matter if it is variable or a signal), all I see is '0' on the screen.
So... The following code properly updates my display unless I uncomment the commented lines. At that point, it just shows '0'.
--currentRegVal := currentRegVal + 1;
--screenVal <= 25;
-- screen holds the values for the current screen
-- The second argument is the row on the screen to be updated
-- The third argument is the value to display there
screen := update_screen(screen, 1, currentRegVal);
screen := update_screen(screen, 0, screenVal + 25);
The problem seems to be stemming from the integer'image attribute (or more accurately, my understanding of it). When I pass in a hardcoded value or a variable that hasn't been altered, it returns what I expect. However, as soon as I modified the variable/signal in ANY way it seems to return the string "0".
Below is my update_screen function:
function update_screen(screen: screenData; reg, regVal: integer) return screenData is
-- A function may declare local variables. These do not retain their values between successive calls,
-- but are re-initialised each time. Array-type parameters may be unconstrained:
constant screenWidth: integer := screen'length(2);
constant strRegVal: string := integer'image(regVal);
constant strRegLen: integer := strRegVal'length;
variable newScreen: screenData := screen;
begin
for dex in 1 to screenWidth loop
if dex <= strRegLen then
newScreen(reg, dex-1) := strRegVal(dex);
else
newScreen(reg, dex-1) := ' ';
end if;
-- The next two ifs were my attempt to figure out what
-- was going on...
--The value itself never seems to be 0... the screen is not all 5's
if regVal = 0 then
newScreen := (others => (others => '5'));
end if;
-- But the string value is "0" if the variable/signal is ever modified...
-- 'd' shows up in the designated row.
if strRegVal = "0" then
newScreen(reg*3, 1) := 'd';
end if;
end loop;
return newScreen;
end update_screen;
A couple important points (added 2011-07-26):
I'm using the Quartus II free (web) edition to design/compile my project.
The code which is updating the variables is in a process.
At the time of the original posting, the only steps I had taken were to compile my code and program an Altera DE2 FPGA board with the result (I wasn't sure how to perform any kind of simulations).
Thanks in advance for any help and advice. Also, as I said, I'm new to VHDL programming, so if there is a much better way to do something I'm doing here, please let me know. I would also greatly appreciate useful links to any resources about the language itself.
Update (2011-07-26):
I downloaded GHDL as Martin Thompson suggested, but I have not actually used it yet because I'm not sure how to go about doing so with my current Quartus II project (or if I even can). I'll have to do some reading before it is useful to me. However, yesterday I managed to install ModelSim-Altera which works directly with Quartus II and allowed me to perform some simulation.
I did my best to set up some waveforms that would allow me to test, and I was at least able to examine the execution of the code which I believed to be failing. However, during simulation, I've verified in multiple ways that the "screen" object does contain the value I want it to contain after the *screen_update* function runs. When running on the Altera DE2, however, it still fails.
Note: I did verify that the screen actually does update by directly setting the value of a particular element on the screen to different values depending on whether or not the currentRegVal is even or odd.
I'll plan on posting some code tomorrow, but for now:
What reasons are there that simulation would provide different results? My guess is something to due with timing, but it is really just a guess. If I am correct, how can I go about trying to resolve the issue?
I guess the problem is related to the fact that you declared strRegVal as a constant. I think it should better be a variable, e.g. something like this might work:
function update_screen(screen: screenData; reg, regVal: integer) return screenData is
...
variable strRegVal: string;
variable strRegLen: integer;
...
begin
strRegVal := integer'image(regVal);
strRegLen := strRegVal'length;
...
end update_screen;
Assuming this code is in a process:
screenVal <= 25;
-... snip...
screen := update_screen(screen, 0, screenVal + 25);
screenVal won't have updated to a new value yet (unless some time passes - a wait statement between the write and the read)

Guess A Number - Ruby Online

I have been trying to create a Ruby program that will be running online where a user can guess a number, and it will say higher or lower. I know it will take a random number store in a variable, then run a loop? With conditionals to check?
Im not asking for full code, the basic structure for I can use this to get me going.
Any idea how i would do this? I found info to create a random number like this:
x = rand(20)
UPDATE: My code I am going to be working with is something like this: http://pastie.org/461976
I would say to do something like this:
x = rand(20)
loop {
# get the number from the user somehow, store it in num
if num == x
# they got it right
break
elsif num > x
# the guess was too high
else
# the guess was too low
end
}
If you're running it online, this structure may not be feasible. You may need to store the guess in the user's session and have a textbox for the guess, and submit it to a controller which would have the above code without the loop construct, and just redirect them to the same page with a message if they didn't get it right.

Resources