Page 1 of 1
if or i don't get it
Posted: Thu Feb 27, 2014 5:09 pm
by DavJans
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.
Re: if or i don't get it
Posted: Thu Feb 27, 2014 5:21 pm
by Klaus
Hi DavJans (David Janssen a.k.a. "Richard Kimble"? Geez, I am old to know that tv-series

)
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
...
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
Re: if or i don't get it
Posted: Thu Feb 27, 2014 5:49 pm
by dunbarx
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
Re: if or i don't get it
Posted: Thu Feb 27, 2014 6:13 pm
by DavJans
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...
Re: if or i don't get it
Posted: Thu Feb 27, 2014 6:46 pm
by mwieder
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
Re: if or i don't get it
Posted: Thu Feb 27, 2014 7:51 pm
by DavJans
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

Re: if or i don't get it
Posted: Thu Feb 27, 2014 7:57 pm
by Klaus
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

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