if or i don't get it

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

Post Reply
DavJans
Posts: 275
Joined: Thu Dec 12, 2013 4:21 pm

if or i don't get it

Post by DavJans » Thu Feb 27, 2014 5:09 pm

if fld "user" <> "254" or fld "user" <> "244" then
answer "Invalid user"
else
to to card 2

I know its wrong because it only answers with Invalid user i cant seem to find the correct way to wright this

alternatively how do I check for a user in a user database? was really only trying to use if/or temporarily anyway.
"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:

Re: if or i don't get it

Post by Klaus » Thu Feb 27, 2014 5:21 pm

Hi DavJans (David Janssen a.k.a. "Richard Kimble"? Geez, I am old to know that tv-series :shock: )
DavJans wrote:if fld "user" <> "254" or fld "user" <> "244" then
answer "Invalid user"
else
to to card 2
You should use AND here!

Or to make it a bit more understandable:

Code: Select all

...
if fld "user" = "254" or fld "user" = "244" then
  to to card 2
else
  answer "Invalid user"
end if
...
:D
DavJans wrote:alternatively how do I check for a user in a user database? was really only trying to use if/or temporarily anyway.
What exactly do you want to check?

Best

Klaus

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10333
Joined: Wed May 06, 2009 2:28 pm

Re: if or i don't get it

Post by dunbarx » Thu Feb 27, 2014 5:49 pm

Hi,

Do you see what Klaus meant? No matter what you have in fld "user", you will get "Invalid User"

My only reason for posting is to mention the other way to do this, which sometimes is easier to understand, and may help you figure out why your first try failed:

if fld "user" = 244 or fld "user" = 254 then proceedAccordingly

The "or"/"and" switch sends you down a different path. Instead of exiting when the conditions are not met, you proceed when they are. Just a mention.

Craig Newman

DavJans
Posts: 275
Joined: Thu Dec 12, 2013 4:21 pm

Re: if or i don't get it

Post by DavJans » Thu Feb 27, 2014 6:13 pm

Very close, my name is David Jansson (with an o not an e). I also grew p in Sweden, when I moved to the US and introduced myself everyone would say "Like the actor?" its all right though, as I get older less and less people know who David Janssen is :)

ok, I get it, for now I will replace or with and.
And what I meant was, eventually I will have a bunch of users and it would be annoying to recompile every time I need to and a new user.
So I need to wright something like

Code: Select all

if fld "user" is in this list over here or db table
then go to card 2
else...
"Det bästa stället att hitta en hjälpande hand är i slutet av din egen arm" förutom här

mwieder
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3581
Joined: Mon Jan 22, 2007 7:36 am
Contact:

Re: if or i don't get it

Post by mwieder » Thu Feb 27, 2014 6:46 pm

Well, those can be two quite different things.
The first part is the easiest

Code: Select all

if fld "user" is among the lines of fld "valid_users" then
  #...do something here
end
For the database part, you'd need to do several steps:

connect to the database
issue a sql query against the open database connection
disconnect from the database
see whether the database query returned a valid response

DavJans
Posts: 275
Joined: Thu Dec 12, 2013 4:21 pm

Re: if or i don't get it

Post by DavJans » Thu Feb 27, 2014 7:51 pm

OK, I can do that, already working with about 10 tables in my application so far, I guess I don't really learn in the conventional order of things :)
"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:

Re: if or i don't get it

Post by Klaus » Thu Feb 27, 2014 7:57 pm

Hi Dave,
DavJans wrote:OK, I can do that, already working with about 10 tables in my application so far, I guess I don't really learn in the conventional order of things :)
:D

OK, in that case just select all possible users from your database and use an identical script like Mark's:

Code: Select all

...
if fld "user" is among the lines of VariableHoldingSQLResult then
  #...do something here
end
...
Best

Klaus

Post Reply