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

bit condition statement in formula

Status
Not open for further replies.

Alcar

Programmer
Sep 10, 2001
595
US
I'm having a hard time setting up the condition statement for a bit instruction like this one:
in c#

int expression = 8191;
int mask = 1;

if (mask = (expression & mask))
{
// do something
}

in the formula I tried this:
IIF (({spLetters;1.Exception} and 1), 1,{spLetters;1.Exception}) = "X"

but it's telling me that my field "{spLetters;1.Exception}" needs to be a boolean (because of the and)

what is the bit logical operator in crystal reports?
 
What are you trying to have Crystal do?

The IIF statement is an if then else

IIF({the field}=5,"Five","Not 5")

or it could be written as:

If {the field}=5 then "Five" else "Not 5"

Mike

 
"and" is a logical operator....Crystal doesn't have any "Bit Logic" capablility to my knowledge. If you want to do that kind of stuff (Bit Masking)in Crystal you would have to create a set of formulas yourself as well as converting the numbers to hex I would imagine. Jim Broadbent
 
I noticed that too Jim.
I solved the problem by making the Bit Logical condition in the SQL statement that populates my report, creating bit fields (yes/no). From there it was a piece of cake creating the formulas.
Thank you for your time
 
No problem....perhaps you can do a post on the preparation of the data for the report so that others can benefit.

I have done "Bit Masking" stuff before but it has been several years ago... Jim Broadbent
 
Given a bit field:

1 = condition 1
2 = condition 2
4 = condition 3
8 = condition 4
16 = condition 5

we can store this information in a single DB field:

condition = 31 (all flagged)

in the SQL Server create a function to get the flags out:

CREATE FUNCTION MaskToBit (@Mask int, @Bit int)
RETURNS int
AS
BEGIN
DECLARE @Result int
Declare @bi int


Set @Result = @Mask & @Bit
if @Result = @Bit
Set @bi = 1
else
Set @bi = 0

RETURN(@bi)
END


then in your stored procedure use this function to create you flag fields from the Logical Bit field:


CREATE PROCEDURE spReportSource
AS
SELECT
dbo.MaskToEx2(MyTable.condition, 1) AS Condition1,
dbo.MaskToEx2(MyTable.condition, 2) AS Condition2,
dbo.MaskToEx2(MyTable.condition, 4) AS Condition3,
dbo.MaskToEx2(MyTable.condition, 8) AS Condition4,
dbo.MaskToEx2(MyTable.condition, 16) AS Condition5
FROM MyTable
WHERE condition > 0


now in my project, I set this stored procedure as the recordsource of my report and I create the formulas for the flags:
(using basic syntax)

if {spReportSource;1.Condition1} = 1 then
formula = "true"
else
formula = "false"
end if


et voila' We have just worked around the bit logical operation for the reports.

hth
 
just a little typo in the stored procedure, the function name is MaskToBit =)
sorry about that
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top