Page 1 of 2

URL and "Contains" on multiple items

Posted: Wed Mar 07, 2012 10:27 am
by Nakia
Hi Again,

trying to search a URL and see if it contains 2 strings.
Using this but in the dictionary doesn't offer any assistance for looking for multiple strings.

If I look for just one item it seems to work just fine...

on checkIfExist
set the defaultFolder to specialFolderPath("Documents")
  if URL ("file:flights.dat") contains "1517" and "UNKNOWN"
then
answer "data exists" with "OK"
else
answer "all clear" with "OK"
end if

end checkIfExist

Re: URL and "Contains" on multiple items

Posted: Wed Mar 07, 2012 12:33 pm
by Klaus
hi Kia,

1. no need to set the defaultfolder every time, just create the complete filename.
2. You need to query both conditions as one complete query, see below
3. "answer" will always show the OK button automatically, so you can save some typing :)

Code: Select all

on checkIfExist
   ## First read the file into a variable
  put url("file:" & specialFolderPath("Documents") & "/flights.dat") into tFlightData

  ## Now check for both conditions
  if tFlightData contains "1517" AND tFlightData contains "UNKNOWN" then
        answer "data exists" with "OK"
   else
       answer "all clear" with "OK"
   end if
end checkIfExist
Best

Klaus

Re: URL and "Contains" on multiple items

Posted: Thu Mar 08, 2012 12:18 am
by Nakia
Can I apply this to reading the URL file itself In place of having to put it into a variable first?
Is it in efficient putting this formation into a variable over and over? I will be performing this task over and over as part
Of an error check in the App.


Also to add further question, I will be using the value of multiple option menus for the string to search against..is it best to place this into variables at handler start also?

Like this????

On checkData
--- read current selections of optionMenu button into variable
put pItemName of fld "button1" into tButtonOne
Put pItemName of fld "button2" into tButtonTwo
Put pItemName of fld "button3" into tButtonThree

--- read flights file into variable
put url("file:" & specialFolderPath("Documents") & "/flights.dat") into tFlightData
Question, will this over write all data in the variable next time it's called or will it add to what's already within?

--- check all three optionMenu buttons to see if data exists for this already in the tFlights variable
if tFlightsData contains tButtonOne and tFlightsData contains tButtonTwo and tFlightsData contains tButtonThree
Then
Answer "data exists"
Else
writeData
End if

End checkData

Re: URL and "Contains" on multiple items

Posted: Thu Mar 08, 2012 1:34 pm
by Klaus
Hi Kia,
Nakia wrote:Can I apply this to reading the URL file itself In place of having to put it into a variable first?
Is it in efficient putting this formation into a variable over and over? I will be performing this task over and over as part
Of an error check in the App.
well, this is a question of efficiency :D
Reading a file from the disk ONCE and storing it into a variable is definitively faster than reading the file EVERYTIME when needed!
Nakia wrote:Also to add further question, I will be using the value of multiple option menus for the string to search against..is it best to place this into variables at handler start also?
I think it will make more sense for you if you put the file into a GLOBAL variable when the stack opens!
this way, you can access the data erverwhere you need it!

Like this:

Code: Select all

on openstack

  # Need to declare it in every script you use the global!
  global gFlightData
  put specialFolderPath("Documents") & "/flights.dat" into tFlightDataFile

  ## Alway check!
  if there is a file tFlightDataFile then
      put url("file:" & specialFolderPath("Documents") & "/flights.dat") into gFlightData
  else
  put empty into dFlightData

   ## and(or optionally
   ## answer "No flight data saved"
 end if

  ## other openstack srtuff here...
end openstack
Then use this global in your script(s) like this:

Code: Select all

On checkData

   ## Tell LiveCode that yopu want to use the GLOBAL varuable 
   global gFlightData

   ---  read current selections of optionMenu button into variable
   put pItemName of fld "button1" into tButtonOne
   Put pItemName of fld "button2" into tButtonTwo
   Put pItemName of fld "button3" into tButtonThree

    --- check all three optionMenu buttons to see if data exists for this already in the tFlights variable
   if gFlightsData contains tButtonOne and gFlightsData contains tButtonTwo and gFlightsData contains tButtonThree then
      Answer "data exists"
    Else
       writeData
  End if
End checkData
## put url("file:" & specialFolderPath("Documents") & "/flights.dat") into tFlightData
## Question, will this over write all data in the variable next time it's called or will it add to what's already within?
PUT... INTO... will always replace the previous content of a variable/container!


Best

Klaus

Re: URL and "Contains" on multiple items

Posted: Fri Mar 09, 2012 12:04 am
by Nakia
Adding it as a global variable sounds great but that means it will only be populated once on stack open which will
Not be suffice. This file constantly changes so it will need to be re populated into the variable every time this function is called so using the the global probably won't work?

Re: URL and "Contains" on multiple items

Posted: Fri Mar 09, 2012 1:31 am
by Klaus
Hi Kia,

is it really neccessary to update the FILE everytime the data changes?
Can't you just update the global variable and write its content to the FILE when the app quits?


Best

Klaus

Re: URL and "Contains" on multiple items

Posted: Fri Mar 09, 2012 1:35 am
by Nakia
Yes it is unfortunately.
The app is a data collection form that writes the data to the file every time a new form is requested hence me wanting to check on new form submission that the data doesn't already exists.

Re: URL and "Contains" on multiple items

Posted: Fri Mar 09, 2012 2:12 am
by Nakia
Or is there a way to Add data to the global variable without replacing the contents currently within?
Like add the text of fld "fld" to tGlobalVariable

Re: URL and "Contains" on multiple items

Posted: Fri Mar 09, 2012 2:14 am
by mwieder
You mean as in

Code: Select all

put field "fld" after tGlobalVariable
?

Re: URL and "Contains" on multiple items

Posted: Fri Mar 09, 2012 3:44 am
by Nakia
So this will add the contents from field "fld" to the already existing contents of the global variable?

Re: URL and "Contains" on multiple items

Posted: Fri Mar 09, 2012 7:28 am
by mwieder
Yep.

Re: URL and "Contains" on multiple items

Posted: Mon Mar 19, 2012 7:34 am
by Nakia
another question on the contains function.

I am comparing the contents of a variable with the contents of a field to see if a number exists. The field has multiple lines with three columns (tab separated)
and column 3 contains the number. now if the field had a value of 1234 in it and i compared a variable that contained 123 i would get a true return..

is there a way I can get the contains to look at the numbers as an entire string?

I.E. only return true if the fld contained exactly what was in the compared variable?

Re: URL and "Contains" on multiple items

Posted: Mon Mar 19, 2012 5:18 pm
by mwieder

Code: Select all

set the wholeMatches to true
That should do the trick.

Re: URL and "Contains" on multiple items

Posted: Mon Mar 19, 2012 9:51 pm
by Nakia
Cool. Thanks, will try this out tonight....

Re: URL and "Contains" on multiple items

Posted: Tue Mar 20, 2012 7:26 am
by Nakia
no good :?
still returning a match....