URL and "Contains" on multiple items
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller
URL and "Contains" on multiple items
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
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
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
Best
Klaus
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
Klaus
Re: URL and "Contains" on multiple items
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
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
Hi Kia,
Reading a file from the disk ONCE and storing it into a variable is definitively faster than reading the file EVERYTIME when needed!
this way, you can access the data erverwhere you need it!
Like this:
Then use this global in your script(s) like this:
## 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
well, this is a question of efficiencyNakia 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.

Reading a file from the disk ONCE and storing it into a variable is definitively faster than reading the file EVERYTIME when needed!
I think it will make more sense for you if you put the file into a GLOBAL variable when the stack opens!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?
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
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
## 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
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?
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
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
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
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.
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
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
Like add the text of fld "fld" to tGlobalVariable
Re: URL and "Contains" on multiple items
You mean as in
?
Code: Select all
put field "fld" after tGlobalVariable
Re: URL and "Contains" on multiple items
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
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?
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
Code: Select all
set the wholeMatches to true
Re: URL and "Contains" on multiple items
Cool. Thanks, will try this out tonight....
Re: URL and "Contains" on multiple items
no good
still returning a match....

still returning a match....