In my BizTalk Decide shape, How can I handle below conditions in one decide shape node?
code == 'code1'
code == 'code2'
code == 'code3'
code == 'code4'
I'm trying to do, this by
(code == 'code1' Or code == 'code2' Or code == 'code3' Or code == 'code4' )
But It is not working, please suggest.
The Decide Shape takes any (mostly) C# formatted condition so you would use:
(code == "code1") || (code == "code2") || (code == "code3") || (code == "code4")
You have to use the double quote since the single quote specifically means char data, not string.
Related
Following condition in if controller is not working
(${__threadNum} =="1" || ${__threadNum} % 5 == "0") && ("${__iterationNum}"=="1")
You have types mismatch in your expression, you should amend it to:
(${__threadNum} ==1 || ${__threadNum} % 5 == 0) && ${__iterationNum} == 1
Also make sure you have Custom JMeter Functions bundle installed, it can be done using JMeter Plugins Manager
In case of any problems take a look at jmeter.log file, it should contain all necessary troubleshooting information.
need to put double quotes... ""
"${__threadNum}"==1 :::
("${__threadNum}"==1 ||"${__threadNum}"==0)&&("${__iterationNum}"==1)
Hi My answer may be helpful for someone else as well
${__groovy(vars.get("country) != "${Current_Country}" || vars.get("State") != "${__V(State_${Counter})}")}
I have the following code:
until (#world.exists? decision || decision == '')
UiHandler.print_error(UiHandler::NO_TILE)
UiHandler.print_turn_message
decision = gets.chomp
end
which should allow the player to skip a turn by entering an empty line. But for some reason the until loop keeps running even when the condition is true
i.e. passing in '1 1' does work and stop the loop, since it exists in world, but passing nothing doesn't, even though puts (#world.exists? decision || decision == '') gives 'true'
What would cause an until loop not to stop even when the condition is met?
Fix is
(#world.exists?(decision) || decision == '')
Otherwise - #world.exists? decision || decision == '' is being treated as #world.exists?(decision || decision == ''), which is not correct expression, you intended to write.
As decision is a string object, which in Ruby is considered as truth value, decision || decision == '' (in the code written by you) will be evaluated as true too. This decision will be passed as a method argument to the method #world.exists? always.
I can't get working this conditional expression
<!--#if expr="$DOCUMENT_NAME!=index.html || $DOCUMENT_NAME!=links.html" -->
while this one without ! before = works perfect
<!--#if expr="$DOCUMENT_NAME=index.html || $DOCUMENT_NAME=links.html" -->
What's the problem? I get no error simply != doesn't work though || with other condition but works for single condition.
This is because = and != are hardly the same operator. Note that, by De Morgan's law (which I also explained in this old post),
a != b || c != d
is equivalent to
a = b && c = d
which is never true for x = a && x = b where a != b.
Changing the binary operator requires changing the conditionals as well to be equivalent.
Thus, by the above logic,
$DOCUMENT_NAME!=index.html || $DOCUMENT_NAME!=links.html
is equivalent to
$DOCUMENT_NAME=index.html && $DOCUMENT_NAME=links.html
which cannot be true as $DOCUMENT_NAME can be "index.html" or "links.html" but not both.
However, the 2nd snippet,
$DOCUMENT_NAME=index.html || $DOCUMENT_NAME=links.html
"works" because there is not the logical never-true fallacy mentioned above. It will be true when $DOCUMENT_NAME is either "index.html" or "links.html".
Some languages/values will violate the above equivalency .. but that is another topic.
Suppose I have this function:
std::string Func1(std::string myString)
{
//do some string processing
std::string newString = Func2(myString)
return newString;
}
How do I set a conditional break when newString has a specific value? (without changing the source)
Setting the condition newString == "my value" didn't work. The breakpoints were disabled with an error overloaded operator not found.
There is a much easier way in Visual Studio 2010/2012.
To accomplish what you are looking for in ANSI use this:
strcmp(newString._Bx._Ptr,"my value")==0
And in unicode (if newString were unicode) use this:
wcscmp(newString._Bx._Ptr, L"my value")==0
There are more things you can do than just a compare, you can read more about it here:
http://blogs.msdn.com/b/habibh/archive/2009/07/07/new-visual-studio-debugger-2010-feature-for-c-c-developers-using-string-functions-in-conditional-breakpoints.aspx
In VS2017, I was able to set the condition as:
strcmp(&newString[0], "my value") == 0
Some searching has failed to turn up any way to do this. Suggested alternatives are to put the test in your code and add a standard breakpoint:
if (myStr == "xyz")
{
// Set breakpoint here
}
Or to build up your test from individual character comparisons. Even looking at individual characters in the string is a bit dicey; in Visual Studio 2005 I had to dig down into the member variables like
myStr._Bx._Buf[0] == 'x' && myStr._Bx._Buf[1] == 'y' && myStr._Bx._Buf[2] == 'z'
Neither of these approaches is very satisfactory. We should have better access to a ubiquitous feature of the Standard Library.
In VS2017 you can do
strcmp(newString._Mypair._Myval2._Bx._Buf,"myvalue")==0
While I've had to work around this using something similar to Brad's answer (plus using DebugBreak() to break right from the code), sometimes editing/recompiling/re-running a bit of code is either too time consuming or just plain impossible.
Luckily, it's apparently possible to spelunk into the actual members of the std::string class. One way is mentioned here -- and though he calls out VS2010 specifically, you can still access individual chars manually in earlier versions. So if you're using 2010, you can just use the nice strcmp() functions and the like (more info), but if you're like me and still have 2008 or earlier, you can come up with a raggedy, terrible, but functional alternative by setting a breakpoint conditional something like:
strVar._Bx._Ptr[0] == 'a' && strVar._Bx._Ptr[1] == 'b' &&
strVar._Bx._Ptr[2] == 'c'
to break if the first three characters in strVar are "abc". You can keep going with additional chars, of course. Ugly.. but it's saved me a little time just now.
VS2012:
I just used the condition below because newString._Bx._Ptr ( as in OBWANDO's answer ) referenced illegal memory
strcmp( newString._Bx._Buf, "my value")==0
and it worked...
#OBWANDO (almost) has the solution, but as multiple comments rightly point out, the actual buffer depends on the string size; I see 16 to be the threshold. Prepending a size check to the strcmp on the appropriate buffer works.
newString._Mysize < 16 && strcmp(newString._Bx._Buf, "test value") == 0
or
newString._Mysize >= 16 && strcmp(newString._Bx._Ptr, "ultra super long test value") == 0
Tried to use strcmp in gdb8.1 under ubuntu18.04, but it doesn't work:
(ins)(gdb) p strcmp("a", "b")
$20 = (int (*)(const char *, const char *)) 0x7ffff5179d60 <__strcmp_ssse3>
According to this answer, strcmp, is a special IFUNC, one can setup condition like this:
condition 1 __strcmp_ssse3(camera->_name.c_str(), "ping")==0
It's pretty ugly, don't want to do it the second time.
This answer gives a much better solution, it use std::string::compare :
condition 1 camera->_name.compare("ping") == 0
In VS2015 you can do
newstring[0]=='x' && newString[1]=='y' && newString[2]=='z'
Comparing string works better than comparing characters
strcmp(name._Mypair._Myval2._Bx._Buf, "foo")==0
This works, but is very inconvenient to use and error prone.
name._Mypair._Myval2._Bx._Buf[0] == 'f' &&
name._Mypair._Myval2._Bx._Buf[1] == '0' &&
name._Mypair._Myval2._Bx._Buf[2] == '0'
You could convert it into a c string using c_str() like so:
$_streq(myStr.c_str(), "foo")
To set a conditional breakpoint in std::string you need to set it on real internal members of std::string. What you see on watch window is simplified.
You can display real structure of a variable in the watch window by using ,! suffix. In your example:
newString,!
For MSVC 2015 – 2019 you can use:
For string that were never longer than 15 characters:
(newString._Mypair._Myval2._Myres < 16) ?
strcmp(newString._Mypair._Myval2._Bx._Buf, "short") == 0 :
false
For (even historically) longer strings:
(newString._Mypair._Myval2._Myres < 16) ? false :
strcmp(newString._Mypair._Myval2._Bx._Ptr, "My_test_str_value_longer_than_16_chars") == 0
Beware:
The variable name is written twice in each condition!
You need whole expression on single line. Use the copy-paste versions bellow.
Universal condition needs to put the test value twice and variable name three times:
(newString._Mypair._Myval2._Myres < 16) ?
strcmp(newString._Mypair._Myval2._Bx._Buf, "My_test_string") == 0 :
strcmp(newString._Mypair._Myval2._Bx._Ptr, "My_test_string") == 0
Notes: use wcscmp instead of strcmp if you are working with std::wstring.
Find more info on small string optimization in C++ https://vorbrodt.blog/2019/03/30/sso-of-stdstring/ includes sample code to find size of string's internal buffer.
All std:string and std::wstring single line versions for your copy paste convenience:
(newString._Mypair._Myval2._Myres < 16) ? strcmp(newString._Mypair._Myval2._Bx._Buf, "short") == 0 : false
(newString._Mypair._Myval2._Myres < 16) ? false : strcmp(newString._Mypair._Myval2._Bx._Ptr, "My_test_str_value_longer_than_16_chars") == 0
(newString._Mypair._Myval2._Myres < 16) ? strcmp(newString._Mypair._Myval2._Bx._Buf, "My_test_string") == 0 : strcmp(newString._Mypair._Myval2._Bx._Ptr, "My_test_string") == 0
(newString._Mypair._Myval2._Myres < 16) ? wcscmp(newString._Mypair._Myval2._Bx._Buf, L"short") == 0 : false
(newString._Mypair._Myval2._Myres < 16) ? false : wcscmp(newString._Mypair._Myval2._Bx._Ptr, L"My_test_str_value_longer_than_16_chars") == 0
(newString._Mypair._Myval2._Myres < 16) ? wcscmp(newString._Mypair._Myval2._Bx._Buf, L"My_test_string") == 0 : wcscmp(newString._Mypair._Myval2._Bx._Ptr, L"My_test_string") == 0
All above copy/paste samples tested on MSVC version 16.9.10 and program for Windows 10.
Looking to improve my IF statement, and I want to keep my code looking pretty
This is what I am currently doing, is it readable, any room for improvement?
SomeObject o = LoadSomeObject();
if( null == o
||
null == o.ID || null == o.Title
||
0 == o.ID.Length || 0 == o.Title.Length
)
I don't have anyone to ask around. That's why I came here in first place. Please don't close my question :(
I always try and avoid complex boolean expressions for the sake of the next guy, but if I had to write an expression that didn't easily go on one line I would format it as follows:
if (value1 == value2 ||
value3 == value4 ||
value5 == value6 ||
value7 == value8) {
executeMyCode();
}
Your verbosity is leading to a less readable code, I think the following format is best:
if ( null == o || null == o.ID || null.Title || 0 == o.ID.Length || 0 == o.Title.Length )
{
// do stuff
}
We all have high resolution/widescreen displays for a reason, there's no reason to lock your code at some horribly short syntax. Also, I would simply create a function named IsIDEmpty so that the code could look like
if ( IsIDEmpty(o) )
{
// do stuff
}
to keep the code simpler & cleaner. The function would perform the actual checks and return a boolean. I'm sure this is something you might have re-use for anyways, plus it serves as a simple way for code to be more self documenting/commenting.
For the simplest formatting of what you have, I would go with one per line.
if(null == o
|| null == o.ID
|| null == o.Title
|| 0 == o.ID.Length
|| 0 == o.Title.Length)
Even better would be if you could refactor the condition such that it fits on one line. I find that a large number of || or && is usually difficult to read. Perhaps you can refactor it out into a function and be left with:
if(myFunction(...))
My rule of thumb: Avoid any format that a semi-smart auto-formatter can't reproduce.
Having a defined set of formats and a automated tool/template/configuration that actually produces code in that format is a big plus, in my opinion.
And if your code is still unreadable after it has been auto-formatted, then chances are that you need to refactor anyway.
I would either put it all on one line if it fits (which this one clearly doesn't). With this, I would put the || consistently at the start or end of line:
if( null == o ||
null == o.ID ||
null == o.Title ||
0 == o.ID.Length ||
0 == o.Title.Length
)
or
if( null == o
|| null == o.ID
|| null == o.Title
|| 0 == o.ID.Length
|| 0 == o.Title.Length
)
You could have >1 condition on a line, the positioning of || is more important I think.
I'm ignoring the fact that null.Title doesn't seem to make much sense
I find it quite distracting, to be honest. Mostly because the '||' start making funny patters.
I much rather prefer something like
if ( o == null || o.ID == null || null.Title ||
o.ID.Length == 0 || o.Title.Length )
or even better, keep it in a single line if possible.
I think it's pretty unreadable.
The affection of putting the constant first always seems a bit odd to me - most compilers can be persuaded to warn if they find an assignment in a conditional.
Then you're testing for null for two different things, then for zero length for two different things - but the important thing is not the length check, but the member you're checking. So I'd write it as
if (o == null ||
o.ID == null || o.ID.length == 0 ||
o.Title == null || o.Title.Length == 0)
Rather than making up a standard for just this one question - I would suggest adopting an existing coding standard for whatever language you are using.
For example:
GNU Coding Standards
http://www.gnu.org/prep/standards/
Code Conventions for the Java Programming Language
http://java.sun.com/docs/codeconv/
.NET Framework General Reference Design Guidelines for Class Library Developers
http://msdn.microsoft.com/en-us/library/czefa0ke.aspx
Generally I'm with TravisO on this, but if there are so many conditions in your if() statement that it just gets crazy long, consider putting in its own little function instead:
bool wereTheConditionsMet()
{
if( NULL == 0 )
return true;
if( NULL == o.ID )
return true;
: : // and so on until you exhaust all the affirmatives
return false;
}
if ( wereTheConditionsMet() )
{
// do stuff
}
It is a lot easier to convey the intent of a well-named predicate function than an endless string of ||s and &&s.
It is not readable.
This is how I do Really Long Ifs(or those I have to twiddle a lot).
if(
o == null ||
o.ID == null ||
o.Title == null ||
o.ID.Length == 0 ||
o.Title.Length == 0
)
For yours, I would do a single line.
if(o == null || o.ID == null || o.Title == null || o.ID.Length == 0 || o.Title.Length == 0)
Or, if you are using C++, I'd do something like this:
if(!o)
{}
if(! (o.ID && o.Title && o.Length))
{}
...since it separates creation from correctness.
However, caveat emptor, I've been accused of bloated LOC due to my fondness for newlines.
Use an automated code formatter, and configure it appropriately.
Write a method like isPresent(String) that checks the String argument for not null and for not empty (zero length).
Rewrite the original conditional to use the new isPresent(String) method, probably all on one line.
I usually do something like:
if(x < 0 || x >= width
|| y < 0 || y >= height)
{
/* Coordinate out of range ... */
}
The first y and x line up in a monospace font, which is nice, and I'm not confused by half-indentions.
This method works best when doing similar comparisons. Otherwise, I usually split up my if's.