Page 1 of 1

Compare text in a variable to text in a FLD

Posted: Tue Aug 17, 2010 12:20 am
by tareq_daher
I am trying to compare a text in a variable to text that is a field. All i want is that if it finds that text to evaluate to true. I have this set up under a mouse up on a button.

Here is the code i have been using.

Code: Select all

on mouseUp
   put the label of button "testChoice" of card "studentname" of stack "writing" into  pItemName
   
   
   if pitemName is "Choose Test Here" then 
      answer " Please Select a Test from this Drop Down Menu"
   else 
      put the label of button "testChoice" into pItemName
   end if
  
--Until here the code works fine and the variable pItemName is not empty, however although the field testsTakenServerFirst of card studentname of stack "writing" does contain that same text as pItemName, it does not evaluate to TRUE, and it will ALWAYS go to card beginnow
   
   if pItemName is not among the lines of field "testsTakenServerFirst" of card "studentname" of stack "writing" then
      go to card "beginnow" 
   else 
      answer "You have taken this test already, choose another one or logout"
   end if
end mouseUp
Thanks !

Re: Compare text in a variable to text in a FLD

Posted: Tue Aug 17, 2010 3:54 am
by Regulae
Hi there,

The problem may be with the use of “is not among the lines of”. “is among” is very specific- the Rev dictionary says about "among":
Comments:
The valueToFind must be a single word, item, or line (whichever chunk type you have specified). If you specify a string containing more than one chunk, the is among operator evaluates to false, even if all the chunks are in the stringToSearch.
... so because you have specified “among the lines of”, unless the whole of the contents of pItemName is on a line all on its own, it won’t be found, for example, if your field testsTakenServerFirst of card studentname of stack "writing" contained three lines:

This is the first line
This is the second line
This is the third line
... “the second” is not among the lines of the field because the words “the second” are only part of a line, whereas “This is the second line” is among the lines of the field, being, indeed, a complete line. You could try:

Code: Select all

if pItemName is not in field "testsTakenServerFirst" of card "studentname" of stack "writing" then
      go to card "beginnow" 
   else 
      answer "You have taken this test already, choose another one or logout"
   end if
This might be what you are looking for.
Regards,
Michael

Re: Compare text in a variable to text in a FLD

Posted: Tue Aug 17, 2010 9:56 pm
by tareq_daher
Micheal ,

That was exactly the problem, "the is among operator evaluates to false, even if all the chunks are in the stringToSearch." so the suggested code worked perfectly.

Thank you for your help

Tareq