if((([txtFldO1.text length] == 0 ) || ([txtFldO2.text length] == 0 ) ||
([txtFldO3.text length] == 0 ) || ([txtFldO4.text length] == 0 ) ||
([txtFldO5.text length] == 0 )) && (([txtFldR1.text length]== 0) ||
([txtFldR2.text length]== 0) || ([txtFldR3.text length]== 0) || ([txtFldR4.text length]== 0) || ([txtFldR5.text length]== 0)))
{
//alert
//return
}
This statement does not work. It does access all of the propeties. Could anyone tell me why?
I need to access one txtFldO and one txtFldR.
To access properties, try SELF
self.txtFld00.text.length
It should be like this.
if([txtFldO1.text length] == 0 || [txtFldO2.text length] == 0 || [txtFldO3.text length] == 0 || [txtFldO4.text length] == 0){
// Code here
}
You don't need to put parentheses before condition. Just put one parentheses like above example.
Hope this help.
Related
Assuming that A = True, B = False and C = True.
Give the results of the following Boolean operations
AB + BC’ (A + B’C) + B
(b) ABC’ + (B + AC’)B + A’
in boolean multiply operation is AND (&&) operation
and plus + operation is OR(||) operation
and ' operator measn NOT(!)
so,
AB + BC’ (A + B’C) + B
can be written as
(A && B) || [(B && (!C)) && (A || ((!B) && C))] || B
PUTTING THE VALUE IN THE ABOVE EQUATION
= (1 && 0) || [(0 && (!0)) && (1 || ((!1) && 1))] || 1
= 0 || [(0 && 1 )&& (1 || (0 && 1)] ||1
= 0 || [(0 && 1) && (1 || 0)] ||1
= 0 || [0 && 1] ||1
= 0 || 0 || 1
= 1
I KNOW IT IS HARD TO FOLLOW BUT THE ANSWER WILL BE 1
AND FOLLOWING THE SAME LOGIC THE ANSWER TO THE 2ND STATEMENT WILL ALSO BE 1
IF YOU WANT TO UNDERSTAND HOW THIS WORKS PLEASE READ THE DOCS
I'm a newbie to swift programming.
I'm trying to get string with the only letters("a-z", "A-Z"), numbers("0-9"), and "-", "_", "*".
when I first tried this code
var new_id = "abc123##%%.."
new_id.filter { ($0 >= "a" && $0 <= "z") || ($0 >= "0" && $0 <= "9") || $0 == "-" || $0 == "_" || $0 == "." }
I got this error
error: the compiler is unable to type-check this expression in reasonable time; try breaking up the expression into distinct sub-expressions
I searched out this error and found out I should break up this code.
However, when I try the below code, actually it works..!
for i in 0..<new_id.count {
let ch: Character = new_id[new_id.index(new_id.startIndex, offsetBy: i)]
if ( (ch >= "a" && ch <= "z") || (ch >= "0" && ch <= "9") || ch == "-" || ch == "_" || ch == "." ) {
new_new_id.append(ch)
}
}
Then, what's the difference between these two codes? I thought the above 'filter' function works same with the below code with 'for'
statement.
let newString = "Hello123..H##^^%%"
let StringData = newString.filter({$0.isLetter})
let NumericData = newString.filter({$0.isNumber})
let caseData = newString.filter({$0 == "_" || $0 == "-" || $0 == "."})
let ChekedData = newString.filter({$0.isNumber || $0.isLetter || $0 == "_" || $0 == "-" || $0 == "."})
print(StringData)
print(NumericData)
print(caseData)
print(ChekedData) ```
I have following query:
var sw = new Stopwatch();
sw.Start();
var model = new StatusModel();
IQueryable<StatusView> statusViewResult = db.StatusViewList;
statusViewResult = statusViewResult.Where(p =>
(query.ClustersSelected.Count == 0 || query.ClustersSelected.Contains(p.Cluster)) &&
(query.ParkNamesSelected.Count == 0 || query.ParkNamesSelected.Contains(p.ParkName)) &&
(query.TurbineNumbersSelected.Count == 0 || query.TurbineNumbersSelected.Contains(p.TurbineNumber)) &&
(query.ModelNamesSelected.Count == 0 || query.ModelNamesSelected.Contains(p.ModelName)) &&
(query.AlarmLevelSelected.Count == 0 || query.AlarmLevelSelected.Contains(p.AlarmLevel)) &&
(query.ParametersSelected.Count == 0 || query.ParametersSelected.Contains(p.Parameter)) &&
(query.TurbineTypesSelected.Count == 0 || query.TurbineTypesSelected.Contains(p.TurbineType)));
sw.Stop();
var d = sw.Elapsed.TotalMilliseconds;
So I am not doing any ToList() so I shouldn't be querying the database at this moment. However I takes around 2 seconds just for building this query - am I missing something here or is this expected?
In Eclipse (4.4) CDT (8.5) on windows (7) the indentation of new lines within if and else if conditions does not make sense to me. Where in eclipse is this set?
I have tried looking in Window > Preferences > C/C++ > Code Style > Formatter but could not see any relevant setting.
An example where I hit the return key as I type the conditions or select the lines and press Ctrl+I ("Fix Indentation"). Note that the first four lines all have the same indentation despite differing levels of nesting. The following fifth line indents two more levels than the preceding line, as does the seventh line both with no apparent relation to the level of nesting.
else if (((wp == SMB_Protocol_Write_Byte) && (qcn >= 1)
&& (rp != SMB_Protocol_Process_Call)
&& (rp != SMB_Protocol_Block_WR))
|| ((wp == SMB_Protocol_Write_Word) && (qcn >=2)
&& (rp != SMB_Protocol_Block_WR))
|| ((wp == SMB_Protocol_Block_Write)
&& (qcn >= (CMD_Number_Bytes_max + 1)))) {
e = EXIT_FAILURE;
}
I would prefer something along the lines of the following:
else if (((wp == SMB_Protocol_Write_Byte) && (qcn >= 1)
&& (rp != SMB_Protocol_Process_Call)
&& (rp != SMB_Protocol_Block_WR))
|| ((wp == SMB_Protocol_Write_Word) && (qcn >=2)
&& (rp != SMB_Protocol_Block_WR))
|| ((wp == SMB_Protocol_Block_Write)
&& (qcn >= (CMD_Number_Bytes_max + 1)))) {
e = EXIT_FAILURE;
}
Is it possible to change this?
Also if someone could comment with an explanation of the current indentation/nesting formatting it would be appreciated!
EDIT: Realised this may be similar to Eclipse JDT Code Formatter: Indent parameter in IF-Statement
Is it possible to change this?
Yes. With the default indentation strategy (K&R built-in) I get the same as you with Ctrl+I, but if I do Ctrl+Shift+F (format code) I get the following.
} else if (((wp == SMB_Protocol_Write_Byte) && (qcn >= 1)
&& (rp != SMB_Protocol_Process_Call)
&& (rp != SMB_Protocol_Block_WR))
|| ((wp == SMB_Protocol_Write_Word) && (qcn >= 2)
&& (rp != SMB_Protocol_Block_WR))
|| ((wp == SMB_Protocol_Block_Write)
&& (qcn >= (CMD_Number_Bytes_max + 1)))) {
If you want to get column alignment, rather than simple indentation on continued lines, create your own formatting profile and change the following:
Indentation tab -> Tab policy to either Spaces only or Mixed
With the default of Tabs only the indents will be to the next tab stop
Line Wrapping tab -> Expressions/Binary Expressions set Indentation policy to Indent on column
This is what you end up with when you format (but not when you simply correct indentation):
} else if (((wp == SMB_Protocol_Write_Byte) && (qcn >= 1)
&& (rp != SMB_Protocol_Process_Call)
&& (rp != SMB_Protocol_Block_WR))
|| ((wp == SMB_Protocol_Write_Word) && (qcn >= 2)
&& (rp != SMB_Protocol_Block_WR))
|| ((wp == SMB_Protocol_Block_Write) && (qcn
>= (CMD_Number_Bytes_max + 1)))) {
Here are screenshots showing the settings:
and
My last elseif statement does not execute even if the conditions are met:
Currency_Exchanage != 'Select...' and all other variables (ETF_Exchanage, Index_Exchanage and Stock_Exchanage) = 'Select...'
Here is the section of code that I am concerned about:
if (strcmp(ETF_Exchanage,'Select...') == 1) && (strcmp(Stock_Exchanage,'Select...') == 1) && (strcmp(Index_Exchanage,'Select...') == 1)...
(strcmp(Currency_Exchanage,'Select...') == 1)
if db == 1 && uni == 1
tickers = gnr_bloomberg; % Analsise Bloomberg natural resources
nrm=1;
elseif db == 1 && uni == 2
tickers = all_bloomberg; % Analsise Bloomberg all
nrm=1;
elseif db == 2 && uni == 1
tickers = gnr_yahoo; % Analsise Yahoo natural resources
nrm=1;
elseif db == 2 && uni == 2
tickers = all_yahoo; % Analsise Yahoo all
nrm=1;
end
else
%Yahoo inputs
if (strcmp(ETF_Exchanage,'Select...') == 0) && (strcmp(Stock_Exchanage,'Select...') == 1) && (strcmp(Index_Exchanage,'Select...') == 1)...
(strcmp(Currency_Exchanage,'Select...') == 1); %Choose exhanges from ETF
tickers = ETF_Yahoo(:,1);
Exchanges = ETF_Yahoo(:,2);
Exchange = ETF_Exchanage;
db=2; %Yahoo Selection
elseif (strcmp(Index_Exchanage,'Select...') == 0) && (strcmp(Stock_Exchanage,'Select...') == 1) && (strcmp(ETF_Exchanage,'Select...') == 1)...
(strcmp(Currency_Exchanage,'Select...') == 1); %Choose exhanges from Index
tickers = Index_Yahoo(:,1);
Exchanges = Index_Yahoo(:,2);
Exchange = Index_Exchanage;
db=2;
elseif (strcmp(Stock_Exchanage,'Select...') == 0) && (strcmp(ETF_Exchanage,'Select...') == 1) && (strcmp(Index_Exchanage,'Select...') == 1)...
(strcmp(Currency_Exchanage,'Select...') == 1); %Choose exhanges from Stock
tickers = Stock_Yahoo(:,1);
Exchanges = Stock_Yahoo(:,2);
Exchange = Stock_Exchanage;
db=2;
elseif (strcmp(Currency_Exchanage,'Select...') == 0) && (strcmp(Stock_Exchanage,'Select...') == 1) && (strcmp(Index_Exchanage,'Select...') == 1)...
(strcmp(ETF_Exchanage,'Select...') == 1); %Choose exhanges from Currency
tickers = Currency_Yahoo(:,1);
Exchanges = Currency_Yahoo(:,2);
Exchange = Currency_Exchanage;
db=2;
else
msg = 'Error occurred.\Only one Yahoo input menue must be used!';
error(msg)
end
end
Any Help would be much appropriated, I can't see where I'm going wrong here. I am using Matlab 2013a.
Put a breakpoint at the elseif statement in question and then check in the command window what your condition evaluates to.
If it does not evaluate like expected, check what the individual terms evaluate to.
It is important to actually test what the conditions evaluate to in matlab, rather than only visually comparing the string values.
Usually by that point you should get a rough idea what is wrong.
However in your case we can't do these steps for you because something is off. Your code condensed to the more reasonable minimal example
if 1 && 1 && 1...
1;
disp('I was here')
end
does not even execute in R2014a since the interpreter complains about '...' being an unexpected matlab expression.