Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller
-
DavJans
- Posts: 275
- Joined: Thu Dec 12, 2013 4:21 pm
Post
by DavJans » Wed Apr 23, 2014 7:40 pm
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
"Det bästa stället att hitta en hjälpande hand är i slutet av din egen arm" förutom här
-
magice
- Posts: 457
- Joined: Wed Mar 18, 2009 12:57 am
Post
by magice » Wed Apr 23, 2014 7:46 pm
Try evaluating the fields outside of the switch, putting a value into a variable accordingly, and using that variable for your case.
-
DavJans
- Posts: 275
- Joined: Thu Dec 12, 2013 4:21 pm
Post
by DavJans » Wed Apr 23, 2014 7:51 pm
I will try that, I also forgot the () : (case1) and (case2)
"Det bästa stället att hitta en hjälpande hand är i slutet av din egen arm" förutom här
-
magice
- Posts: 457
- Joined: Wed Mar 18, 2009 12:57 am
Post
by magice » Wed Apr 23, 2014 7:56 pm
DavJans wrote:I will try that, I also forgot the () : (case1) and (case2)
don't forget break as well
-
DavJans
- Posts: 275
- Joined: Thu Dec 12, 2013 4:21 pm
Post
by DavJans » Wed Apr 23, 2014 8:02 pm
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.
"Det bästa stället att hitta en hjälpande hand är i slutet av din egen arm" förutom här
-
Klaus
- Posts: 14199
- Joined: Sat Apr 08, 2006 8:41 am
-
Contact:
Post
by Klaus » Wed Apr 23, 2014 8:07 pm
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
-
magice
- Posts: 457
- Joined: Wed Mar 18, 2009 12:57 am
Post
by magice » Wed Apr 23, 2014 8:07 pm
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.
-
DavJans
- Posts: 275
- Joined: Thu Dec 12, 2013 4:21 pm
Post
by DavJans » Wed Apr 23, 2014 8:39 pm
magice wrote:
don't forget break as well
Remember reminding me about this?
It fixed it for me
"Det bästa stället att hitta en hjälpande hand är i slutet av din egen arm" förutom här