If results are not >= "Number" then show blank - crystal-reports-2008

New to building Crystal Reports and SQL.
I'm trying to write a script to where if results is >= 12.1 then show result else show no results.
Same goes for the <=9.9.
Here is what I have so far:
if {Test.Name} = "xyz" and {TestResults.numresult}>= 12.1 then {TestResults.numresult} else "";
Below is an image showing the same results across the board. I just want the results to show when its <=9.9 or >=12.1.
Hope this make sense.

Your statement returns a number from one branch and a string from the other. It must return the same data type.
One option is to use a True/False expression in a Suppress expression.
Another option is to return a zero in the other branch and use number formatting to suppress if zero (it's a built-in option for numbers).
Another option is to modify your expression so it returns a string from both branches. For example:
if {Test.Name} = "xyz" and {TestResults.numresult}>= 12.1 then ToText({TestResults.numresult}, 1, ",") else "";
The 1 argument requests 1 decimal point. The "," argument requests a comma as thousands separator. You can adjust those to match your number formatting requirements.

Related

exctract substring from a large string under certain conditions in painless

In painless I would like to create a script which reads a keyword field called 'objldn' and extracts only five consecutive characters sometimes present in a precise position. Infact, in the keyword field 'objldn' there are a large variety of long strings among which there are some of them with a third underscore. After the third underscore, if it is present, I can fetch the consecutive 5 chars.
Whith the following lines of code I implement what I want:
def LU = doc['objldn'].value.splitOnToken('_');
return LU[3].substring(0, 5);
But the system returnes an error message "out of bounds":
Request error: array_index_out_of_bounds_exception, Index 3 out of
bounds for length 3 in "def LU =
doc['objldn'].value.splitOnToken('_'); ..." (Painless script)
error executing runtime field or scripted field on index pattern
return LU[3].substring(0, 5);
^---- HERE
may be it is due to the fact that many strings do not have the third underscore or do not even have one and therefore I need to implement firstly a IF statement which evaluates if a third underscore is in the string and only if it is present it proceeds to execute splitOnToken()... but I am not able to do it correctly. Can you help me to add the IF statement in the script please?
Why not simply checking the length of the LU array?
def LU = doc['objldn'].value.splitOnToken('_');
return LU.length >= 4 ? LU[3].substring(0, 5) : null;

SSRS takes out leading zero if the Customer Ref contains leading zero

I have the following situation of running SSRS report with Report Builder 3.0 (SQL Server 2012).
The data field CustomerRef contains Customer Reference No which may have Cust1234 or 00001234. I want to retain the Cust1234 whereas to trim out the leading zero of 00001234 with below expression.
=IIF(Fields!CustomerRef.Value.Contains("Cust"), Fields!CustomerRef.Value, CStr(Cint(Fields!CustomerRef.Value)))
As a result, Customer Ref No with 00001234 can be changed to 1234. However, all other Custxxxx returns #Error. How do I solve this?
This is not tested but try this
=IIF(Fields!CustomerRef.Value.Contains("Cust")
, Fields!CustomerRef.Value
, CStr(Cint(
IIF(Fields!CustomerRef.Value.Contains("Cust")
,0
,Fields!CustomerRef.Value)
)
)
)
The idea here is that is the field does contain "Cust" then the CINT function sees 0 as the operand rather than the CUst1234 which will fail, even though that but of code will never get executed.
Another option (again untested) is the simpler
=IIF(Fields!CustomerRef.Value.Contains("Cust")
, Fields!CustomerRef.Value
, CStr(VAL(Fields!CustomerRef.Value))
)
As VAL() will try to turn a string into a value by extracting only the numeric parts of the string, it does not fail when presented with a string as an argument.

Visual Studio 2012 Form1.vb user input validation

I have connected the sql database to my vb project and the last feature I need is to validate the user input. Two of the textboxes needs to be validated when adding a new record.
txtName is the first textbox that consists of the following format: BCO103/T1/01 . 'BCO' will always stays the same, however the rest needs to be input by the user. Letters and numbers needs to stay in exact the same place.
txtModuleID is the second textbox that needs to be validated. The data for this field looks like this: BCO120 . Yet again, BCO will always stay the same, however the 3-digit number will change.
Im sure you can use substrings for this
for example:
If txtModuleID.Text.Substring(0,2) = "BCO" And txtModuleID.Text.Substring... etc Then 'add other conditionals
blnValidated = True
Else
blnValidated = False
End If
If txtModuleID.Text.Trim.ToUpper().SubString(0,2).equals("BCO") and len(txtModuleID.Text.Trim) = 6 Then
If txtModuleID.Text.Trim.SubString(3,5).isNumeric() Then
//valid input
Else
//message prompt that last 3 digits of the input is not numeric
End If
Else
//message prompt that input has invalid format and that input must start with BCO
End IF
Substring (0, 2) means from 0 until 2... getting the sub string of the input with letters in index 0, 1 and 2. The rest follows.
As for the first input, please do expound. I didn't quite catch how you want it to be validated.

how to check whether the string taken through gui is a binary string in matlab?

I am working on a watermarking project that embeds binary values (i.e 1s and 0s) in the image, for which I have to take the input from the user, and check certain conditions such as
1) no empty string
2) no other character or special character
3) no number other than 0 and 1
is entered.
The following code just checks the first condition. Is there any default function in Matlab to check whether entered string is binary
int_state = get(handles.edit1,'String'); %edit1 is the Tag of edit box
if isempty(int_state)`
fprintf('Error: Enter Text first\n');
else
%computation code
end
There is no such standard function, but the check can be easily implemented.
Use this error condition:
isempty(int_state) || any(~ismember(int_state, '01'))
It returns false (no error) if the string is non-empty and composed of '0's and '1's only.
The function ismember returns a boolean array that indicates for every character in int_state whether it is contained in the second argument, '01'. The advantage is that this can be generalized to arbitrary sets of allowed characters.
I think the 2nd and 3rd can be combined together as 1 condition: your input string can only be a combination of 0 and 1? If it is so, then a small trick with findstr can do that:
if length(findstr(input_str, '1')) + length(findstr(input_str, '0')) == length(input_str)
condition_satisfied;
end
tf = isnumeric(A) returns true if A is a numeric array and false otherwise.
A numeric array is any of the numeric types and any subclasses of those types.
isnumeric(A)
ans =
1 (when A is numeric).

Select in ADO (vb6) with a numeric variable

Excuse me, occasionally I refer with some problem that maybe it's already been fixed. In any case, I would appreciate a clarification on vs.
I have a TariffeEstere table with the fields country, Min, Max, tariff
from which to extract the rate for the country concerned, depending on whether the value is between a minimum and a maximum and I should return a single record from which to extract its tariff:
The query is:
stsql = "Select * from QPagEstContanti Where country = ' Spain '
and min <= ImpAss and max >= ImpAss"
Where ImpAss is a variable of type double.
When I do
rstariffa.open ststql,.....
the recodset contains a record if e.g. ImpAss = 160 (i.e. an integer without decimals), and then the query works, but if it contains 21,77 ImpAss (Italian format) does not work anymore and gives me a syntax error.
To verify the contents of the query string (stsql) in fact I find:
Select * from QPagEstContanti Where country = 'Spain' and min < = 21,77 and max > = 21,77
in practice the bothering and would like a comma decimal, but do not know how do.
I tried to pass even a
format (ImpAss, "####0.00"),
but the value you found in a stsql is 21,77 always.
How can I fix the problem??
It sounds like the underlying language setting in SQL is expecting '.' decimals instead of ',' decimal notation.
To check this out - run the DBCC useroptions command and see what the 'language' value is set to. If the language is set to English or another '.' decimal notation - it explains why your SQL string is failing with values of double.
If that's the problem, the simplest way to fix it is to insert the following line after your stsql = statement:
  stsql = REPLACE(stsql, ",", ".")
Another way to fix it would be to change the DEFAULT_LANGUAGE for the login using the ALTER LOGIN command (but this changes the setting permanently)
Another way to fix it would be to add this command to the beginning of your stsql, which should change the language for the duration of the rs.Open:
  "SET LANGUAGE Italian;"

Resources