Just trying to do a simple case function in powerbuild.
I have a table
client_notes
A!, B!, C!
case(client_notes when '%A!%' then 'Cash1' else "Cash2")
It compiles OK but when I run it, it says Cash2.
Shouldn't it say Cash1?
What's the context here? Is this in PowerScript or in a datawindow expression, or in the SQL source of the datawindow?
And what version/build of PB are you using?
What it should "say" [sic] all depends on the value of "client_notes" at runtime. It will only return the string 'Cash1' when the value of client_notes is exactly equal to the string '%A!%'.
What set of data are you running this against? Show some sample data.
-Paul Horan-
I have never seen a "LIKE" expression used in the expression painter but it might be possible. I gave it a quick try and wasn't able to. I would agree with what Matt said, except your expression doesn't have the important "LIKE" keyword so it is matching exactly on your string and of course not matching so always getting Cash2.
I've wanted to use > or < in CASE statements before and had problems too, the WHEN seems to be pretty 'dumb' and not able to handle anything other than a value.
This works not as elegant as a case statement though.
if ( client_notes like '%A!%' , 'Cash1',
if ( client_notes like '%B!%' , 'Cash2',
if ( client_notes like '%C!%' , 'Cash3',
'Cash?' ) ) )
What programmer doesn't like a challenge? None of these work but you probably get the thought process I was going through.
case ( ('%' + client_notes + '%') when (like 'A1') then 'Cash1' else 'Cash2' )
case ( '%A1%' when (like 'A1') then 'Cash1' else 'Cash2' )
case ( ( '%bbb%' like 'A1' ) when true then 'Yah' else 'Nah' )
No cigar on CASE...
You could use a global-function, but then again you could write a database function too and it doesn't really solve what you wanted to do. I recall wanting to use like inside a CASE statement more than once and I don't recall getting it to work. I can also recall trying to do something like case variable_a when '4:20' then 'Celebrate' when > '4:20' then 'Too late' else 'Later'
This compiles but do not think it would work due to the comparison variable needing to be different.
case( if ( client_notes like '%' + client_notes + '%', client_notes , 'X')
when 'A1' then 'Cash1'
when 'A2' then 'Cash2'
else 'use nested if instead')
Well, if you wanted to try it as a datawindow computed field, you could use the "brute force" method.
CASE (client_notes
WHEN 'A!' THEN 'Cash'
WHEN 'A!, B!' THEN 'Cash, Check'
WHEN 'A!, B!, C!' THEN 'Cash, Check, Money Order'
WHEN 'A!, B!, C!, D!' THEN 'Cash, Check, Money Order, Card'
WHEN 'B!' Then 'Check'
...
Else '')
In the RetrieveRow event, it might look like this:
string ls_result = ''
string ls_client_notes
If row > 0 then
ls_client_notes = this.getItemString( row, 'client_notes')
If pos( ls_client_notes, 'A!' ) > 0 then ls_result = 'Cash'
If pos( ls_client_notes, 'B!' ) > 0 then
If len( ls_result ) > 0 then
ls_result += ', Check'
Else
ls_result = 'Check'
End if
End if
If pos( ls_client_notes, 'C!' ) > 0 then
If len( ls_result ) > 0 then
ls_result += ', Money Order'
Else
ls_result = 'Money Order'
End if
End if
If pos( ls_client_notes, 'D!' ) > 0 then
If len( ls_result ) > 0 then
ls_result += ', Card'
Else
ls_result = 'Card'
End if
End if
this.setItem( row, 'client_notes', ls_result ) // if you want it back in the same column
End if
-Paul-
Related
I've wrote the following Doctrine query:
$query3 = $this->entityManager
->createQueryBuilder()
->select('t.textDomain , t.translationKey , t.languageIso , t.translationDate')
->from(
'AMDatabase\Entity\TheVerse\TranslationsMasters',
't'
)
->groupBy('t.languageIso')
->orderBy(
't.translationDate',
'DESC'
);
// the values of $key2 array are:
// en-US
// es-MX
// es-PR
foreach( $translation AS $key2=>$value2 ) {
if ( $key2 == 'en-US' ) {
$query3
->orWhere(
$query3->expr()
->like(
't.languageIso',
':languageIso'
)
)
->setParameter(
'languageIso',
$key2
);
}
}
$result3 = $query3->getQuery()
->getArrayResult();
How do I have the query search for all 3 language ISO's at the same time?
With "if ( $key2 == 'en-US' ) {" the query executes and gives me the expected result.
But if I remove "if ( $key2 == 'en-US' ) {" there are no search results.
I thought by using "orWhere" it would keep adding conditions to the query (where en-US will still produce a match).
In haven't ever been able to get orWhere to function the way I think it should. It might be that you need a Where in your opening definition before you can add an orWhere later. You might have to use the nested orX statement like this instead:
$query3->andWhere($query3->expr()->orX(
$query3->expr()->like('t.languageIso', $query3->expr()->literal('en-US')),
$query3->expr()->like('t.languageIso', $query3->expr()->literal('es-MX')),
$query3->expr()->like('t.languageIso', $query3->expr()->literal('es-PR'))
));
You can't develop the statement through a loop. But, since you've only got three criteria, it's easy enough to write out.
I want to get pixel color from a game and react.
So I have this sript:
#include <Color.au3>
Local $pause = False;
$WinName = "Game" ; Let's say there is a game with this name =)
$hwnd = WinGetHandle($WinName) ; Checked handle with powershell and Au3Info, handle is correct
local $res
Opt("PixelCoordMode", 2);
HotKeySet("{F10}", "exitNow");
HotKeySet("{F11}", "Pause");
While 1
;WinWaitActive($hwnd) ; The script stops here if it is uncommented no matter if window is active or not
if ( $pause ) Then
$res = GetPos();
ConsoleWrite ( StringFormat ("Result color: %s %s", $res[0], $res[1] ) )
Sleep (1000)
EndIf
WEnd
Func exitNow()
Exit
EndFunc
Func Pause()
$pause = Not $pause
EndFunc
Func GetPos()
local $var = Hex(PixelGetColor(5, 5, $hwnd)) ; Only works in windowed mode, FullScreen return some random colors like 00FFFFFF or 00AAAAAA
$var = StringTrimLeft($var,2) ; Removing first 2 numbers they r always 00
local $var1 = Hex(PixelGetColor(15, 5, $hwnd)) ; Only works in windowed mode, FullScreen return some random colors like 00FFFFFF or 00AAAAAA
$var1 = StringTrimLeft($var1,2) ; Removing first 2 numbers they r always 00
local $result[2] = [ $var, $var1 ]
return $result
EndFunc
Main script should before window is active and only then should try to GetPixelColor but that never happens, no matter what I do, i've tried WindowActivate still no result.
a) - What am I doing wrong ? Or may be there is another way to check if window is currently active ?
So at the moment I start script disabled, and when I activate window manually I press F11 to enable.
b) - PixelGetColor only works if game is running in Windowed mode, if it's a fullscreen mode result is unpredictable. Is there a way to make PixelGetColor work in fullscreen.
I've tried to run game x32, x64, DX9 and DX11 in different combinations Fullscreen result is just wrong.
ADDED:
Now While looks like this and that works :)
Thanks to Xenobeologist!!!
While 1
$hwnd = WinGetHandle('[Active]');
If ( $pause ) Then
If WinGetTitle($hwnd) <> $WinName Then
Pause()
ContinueLoop
EndIf
$res = GetPos();
ConsoleWrite ( StringFormat ("Result color: %s %s", $res[0], $res[1] ) )
Sleep (1000)
Else
If WinGetTitle($hwnd) = $WinName Then
Pause()
ContinueLoop
EndIf
EndIf
WEnd
a) is now solved
b) is still not solved. One more thing, topic of this question doesn't say anything bout this question, should add info bout this into the topic or it's better to start a new thread? a) was my main question, it would be prefect to solve b) as well but I can live without it. As far as I understood it's much more complicated. What do you think?
ADDED2:
As far as I understand problem b) can be solved by using more complex code. Here http://www.autohotkey.com/board/topic/63664-solved-imagesearch-failure-wdirectx-fullscreen-gamewin7/ was discussed pretty same problem. It's AHK and ImageSearch function, but im pretty sure that the reason I get wrong colours in fullscreen is the same. I don't want to complicate code that much and PrintScreen is too slow so I'll use windowed mode and wont be bothering with b).
Does this help?
#include <MsgBoxConstants.au3>
$handle = WinGetHandle('[Active]')
ConsoleWrite('!Title : ' & WinGetTitle($handle) & #CRLF)
ConsoleWrite('!Process : ' & WinGetProcess($handle) & #CRLF)
ConsoleWrite('!Text : ' & WinGetText($handle) & #CRLF)
Sleep(Random(10, 3000, 1))
If WinActive($handle) Then MsgBox($MB_SYSTEMMODAL, "", "WinActive" & #CRLF & "Scite ")
In Rails/Haml
I know this works
%i.class{:class => (name ? "arrow-up" : "arrow-down")}
I also know that I can make a helper function
%i.class{:class => (getArrowClass name)}
def getArrowClass value
if value == 1
return 'arrow-up'
elsif value == 0
return 'arrow-down'
else
return ''
end
end #getArrowClass
For some reason, whenever I do the helper way it messes up my view (tables don't stick to their places), so now my question is how can I do the if elsif else in the class using the first method.
something like that
%i.class{:class => (if name then "arrow-up" elsif "arrow-down" else "")}
Please try with
%i.class{:class => ((name == 1) ? "classup" : (name == 0) ? "classdown" : "")}
How to check if the string contains only / symbol in it ? The string may have more than one / symbols with white spaces in between. In such cases i want to consider that the string is empty.
In c# the answer would be:
if (yourText.Count(x => (x != '/') && (x != ' ')) > 0)
{
//not empty
}
Basicly: "if the count of all the characters which are not "/" or a space is greater than 0"
I have not done VB in a while, but translating it should not be hard. You could just do for-loop approach
Dim isEmpty as Boolean = true;
For (Dim i as Integer = 0 to yourText.Length - 1)
If (yourText[i] <> "/"C And yourText[i] <> " "C) Then
isEmpty = false;
End If
Next
Again, I am doing this completely from memory, so excuse me if my syntax is off. Correct my code if I have an error.
I have, what I thought was a pretty straight-forward query.
In normal Sql this would read:
SELECT [column names]
FROM agentscheduledetail
WHERE (date = '2012-07-04') AND
(
exception = 'Break (No Sign Off)' OR
exception = 'Break' OR
exception = 'Break (Signed Out)'
)
This returns approx 900 records.
However, when I try to enter this into my controller, I end up with around 300,000 records - so I think my AND and ORs are not working. I've tried Linqer, but can't get it to work (I'm aware this may not be actual LINQ but the equivalent query in VS - if there is a linq version... I'd be grateful for that too if possible).
My controller query is:
var dte = DateTime.Today;
return View(db.agentscheduledetails.Where
(
d => d.date == dte && d.agentName.StartsWith("ta") &&
(
d.exception == "Break (No Sign Off)" ||
d.exception == "Break" ||
d.exception == "Break (Signed Out)"
)
).ToList()
);
Can anyone either a) let me know where I'm going wrong with my && || (and/or), or b) is there a way of stepping through the code in VS, to see what the above query translates to in normal SQL so I can try to figure out where I'm going wrong?
Thanks for any help,
Mark
The following is perhaps a simplified version of what you are trying to do, also your LINQ contains an additional statement compared to the SQL where it is comparing the agent name?
var currentDate = DateTime.Today;
var exceptionTypes = new List<string>() { "Break (No Sign Off)",
"Break", "Break (Signed Out)" };
db.agentscheduledetails.Where(d => d.date == currentDate &&
exceptionTypes.Contains(d.exception));
One thing that you could try is getting hold of a copy of LinqPad, this will let you run your LINQ statement against a database and will show you what the generated SQL statement is.
Aside from anything else,
d.agentName.StartsWith("ta")
does not appear in your original sql...?