Page 1 of 1
switch, field is blank or not?
Posted: Wed Apr 23, 2014 7:40 pm
by DavJans
right now I'm getting nothing
Code: Select all
switch
case fld "Job" <> "" and fld "Emp" = ""
put revQueryDatabase( theConnectionID, "SELECT * FROM cjp WHERE job='" & tJob & "'") into theCursor
case fld "Emp" <> "" and fld "Job" = ""
put revQueryDatabase( theConnectionID, "SELECT * FROM cjp WHERE employee='" & tEmp & "'") into theCursor
case fld "Emp" = "" and fld "Job" = ""
put revQueryDatabase( theConnectionID, "SELECT * FROM cjp") into theCursor
case fld "Emp" <> "" and fld "Job" <> ""
put revQueryDatabase( theConnectionID, "SELECT * FROM cjp WHERE employee='" & tJob & "' and job='" & tEmp & "'") into theCursor
end switch
Re: switch, field is blank or not?
Posted: Wed Apr 23, 2014 7:46 pm
by magice
Try evaluating the fields outside of the switch, putting a value into a variable accordingly, and using that variable for your case.
Re: switch, field is blank or not?
Posted: Wed Apr 23, 2014 7:51 pm
by DavJans
I will try that, I also forgot the () : (case1) and (case2)
Re: switch, field is blank or not?
Posted: Wed Apr 23, 2014 7:56 pm
by magice
DavJans wrote:I will try that, I also forgot the () : (case1) and (case2)
don't forget break as well
Re: switch, field is blank or not?
Posted: Wed Apr 23, 2014 8:02 pm
by DavJans
ok, so I tried this
Code: Select all
if fld "Job" <> "" then
put 1 into tcJob
else
put 0 into tcJob
end if
if fld "Emp" <> "" then
put 1 into tcEmp
else
put 0 into tcEmp
end if
put tcJob & tcEmp into tcJobEmp
put tcJobEmp into fld "Field11"
if theConnectionID is an integer then
## Query the database for data
switch
case tcJobEmp = "10"
put revQueryDatabase( theConnectionID, "SELECT * FROM cjp WHERE job='" & tJob & "'") into theCursor
case tcJobEmp = "01"
put revQueryDatabase( theConnectionID, "SELECT * FROM cjp WHERE employee='" & tEmp & "'") into theCursor
case tcJobEmp = "00"
put revQueryDatabase( theConnectionID, "SELECT * FROM cjp") into theCursor
case tcJobEmp = "11"
put revQueryDatabase( theConnectionID, "SELECT * FROM cjp WHERE employee='" & tJob & "' and job='" & tEmp & "'") into theCursor
end switch
I added Field11 just to see that the if/else is working and it is
but I still get nothing
it has to be related to my switch statement, befor I added the Emp, and I just had an If/else statement with job only it worked fine.
Re: switch, field is blank or not?
Posted: Wed Apr 23, 2014 8:07 pm
by Klaus
Hi DavJans,
as magice said, you left out the neccessary BREAKs in the switch!
Code: Select all
...
switch
case tcJobEmp = "10"
put revQueryDatabase( theConnectionID, "SELECT * FROM cjp WHERE job='" & tJob & "'") into theCursor
BREAK
case tcJobEmp = "01"
put revQueryDatabase( theConnectionID, "SELECT * FROM cjp WHERE employee='" & tEmp & "'") into theCursor
BREAK
case tcJobEmp = "00"
put revQueryDatabase( theConnectionID, "SELECT * FROM cjp") into theCursor
BREAK
case tcJobEmp = "11"
put revQueryDatabase( theConnectionID, "SELECT * FROM cjp WHERE employee='" & tJob & "' and job='" & tEmp & "'") into theCursor
BREAK
end switch
...
If you leave out BREAK then ALL cases will be executed
Best
Klaus
Re: switch, field is blank or not?
Posted: Wed Apr 23, 2014 8:07 pm
by magice
Why not simplify this, and eliminate the switch. Just have four separate if statements. In other words, take the actions from your switch, and put them into the if statements that do your evaluation.
Re: switch, field is blank or not?
Posted: Wed Apr 23, 2014 8:39 pm
by DavJans
magice wrote:
don't forget break as well
Remember reminding me about this?
It fixed it for me