Page 1 of 2
Filtering a string with a string
Posted: Mon Apr 24, 2017 7:31 pm
by Zood
Hello,
As a hobby-programmer i'd like to make a calendar-sort application for OSX.
I have a csv-file (yes iknow, not the most ideal format according to some

) where i store all the reservations per line
(so a reservation would be in format "DATE,NAME,TIME,PHONENUMBER,NUMBEROFPERSONS" -> "01/02/2017 , FISHER , 18:00 , 0515531415 , 4"
To view the reservations per day i wanted to use a field-view where I can filter the information given by the CSV-file to the date selected by the user.
I know how to use the filter-function in the form of: | filter lines of field "XXX" with "02*" | where I can see all the reservations made on the second day of every month.
The problem is that the "O2*" part is a constant which can not be altered later on, lets say when the application is running and I am not altering the code.
Is there some sort of way to use the "Filter"-command with a string?
for example:
Put field "TodaysDate" into Date -> Own input in the field : 01/02/2017
filter lines of field "Reservations" with Date
The result when I try to run it is no error, but no data appears in the targetfield?
I would appreciate any help or ideas!
Thanks in advance

Re: Filtering a string with a string
Posted: Mon Apr 24, 2017 7:37 pm
by Klaus
Hi Zood,
1. welcome to the forum!
2. FYI: DATE is a reserved word, use tDate or something!
3. Do like this, this is called "concatenation" (= building s string):
...
## Create the filter string:
put field "TodaysDate" & "*" into tDate
filter lines of field "Reservations" with tDate
...
Best
Klaus
Re: Filtering a string with a string
Posted: Mon Apr 24, 2017 10:09 pm
by dunbarx
Many ways around this.
Have you ever used arrays? They are very convenient and should not be too scary. You could eliminate any csv issues as well as creating associative pairs of data. Those pairs stand alone, unencumbered by string deconstruction and/or construction, and any baggage that might tag along.
The user would enter data, and you would then:
Code: Select all
put dateValue into myCalendar[tDate]
put nameValue into myCalendar[tName]
put timeValue into myCalendar[tTime]
put phoneValue into myCalendar[tPhone]
put crowdValue into myCalendar[tCrowd]
Then you only need to:
Code: Select all
put myCalendar[tPhone] into fld targetField
and so forth...
Craig Newman
Re: Filtering a string with a string
Posted: Tue Apr 25, 2017 3:52 pm
by Zood
Wow, Thanks for the fast replies!
I implemented the way Klaus has described, worked like a charm!
I now have a functional calendar where the data can be added to a CSV-file and put into 7 fields (per week).
The issue I am now bumping into is the deleting-aspect..
I do not wish to delete the lines, rather use the "strikethrough"-option and turn the text-color to red for people to actually see that it has been canceled and not wonder where the data went

For this I have the following code:
on mouseUp
set the foregroundcolor of line X to red
set the textstyle of line X to "Strikethrough" -> doesn't work
end mouseUp
is there a way to interact with a specific line in the field to be able to perform these actions?
to dunbarx: No, i have never used arrays. I am a hobby-programmer "working" mainly in swift & C+ currently giving livecode a try!
would the arrays eventually have to be put in a CSV-file as a database? My project works from a CSV-file stored in the cloud to be able to access the same information from multiple computers.
Each line in the CSV-file contains a date, name, number, number of persons etc and needs to be called by date.
As the user output in the arrays (I think) need to be put all together into 1 variable (lets say myCalendar[tGlobal])? then pass that specific array onto the targetfield?
Thanks in advance!
Re: Filtering a string with a string
Posted: Tue Apr 25, 2017 4:10 pm
by Klaus
Hi Zood,
LC is asking itself "line X of WHAT []###ΒΆΒΆ?"
Add the field description, use the correct style and it will work:
Code: Select all
...
set the forgroundcolor of line X OF FIELD "your field here" to red
set the textstyle of line X OF FIELD "your field here" to "strikeout"
## wrong style -> "Strikethrough"
## If in doubt always check the dictionary!
...
Best
Klaus
Re: Filtering a string with a string
Posted: Tue Apr 25, 2017 4:18 pm
by Zood
Hey Klaus,
Thanks for the VERY! fast reply!
I noticed in the dictionary indeed that I had my spelling mixed up.
Do you have an idea as to how to select a specific line through user interaction?
For example:
if i click on line 3 of field "Container"
then I click on a button with:
on mouseUp
set the foregroundcolor of line 3 of field "Container" to red
set the text style of line 3 of field "Container" to "strikeout"
end mouseUp
This would work as I wanted to except that the "line 3" could be replaced by the highlightedLine-command:
put the highlightedLine of field "Container" into tHighlitedLine
then change the code of the button to:
on mouseUp
set the foregroundcolor of tHighlitedLine of field "Container" to red
set the text style of tHighlitedLine of field "Container" to "strikeout"
end mouseUp
The problem is that I cannot select a line in the field "Container", as if there is no user interaction possible with the specific field?
Is this an option from the property-inspector or have I picked the wrong sort of field?
Thanks in advance!
Re: Filtering a string with a string
Posted: Tue Apr 25, 2017 4:27 pm
by Klaus
Hi Zood,
check "listbehavior" in the inspector for your field!
Best
Klaus
Re: Filtering a string with a string
Posted: Tue Apr 25, 2017 4:29 pm
by Klaus
Just saw this one, tHighlitedLine will only contain the NUMBER of your line, so this will not work:
Code: Select all
on mouseUp
set the foregroundcolor of tHighlitedLine of field "Container" to red
set the text style of tHighlitedLine of field "Container" to "strikeout"
end mouseUp
Do this:
Code: Select all
on mouseUp
set the foregroundcolor of LINE tHighlitedLine of field "Container" to red
set the text style of LINE tHighlitedLine of field "Container" to "strikeout"
end mouseUp
Re: Filtering a string with a string
Posted: Tue Apr 25, 2017 4:33 pm
by Zood
Hey Klaus,
Thanks for the update!
I have list-behaviour checked!
Whenever I try to highlight a line however it only clicks certain parts of the line, not the entire line itself.
Is there a way around this?
Thanks in advance!
Re: Filtering a string with a string
Posted: Tue Apr 25, 2017 4:37 pm
by Klaus
Hm, should work out of the box, see attached screenshot!?
Any other scripts in the way?
Re: Filtering a string with a string
Posted: Tue Apr 25, 2017 4:43 pm
by Zood
Hey Klaus,
Got it! I put "Auto Hilite" & "List behaviour" & "multi-line" & "non-contiguous" all to true and it worked.
It is as they say, when one problem is solved 3 more appear:
- I can't "unselect" a line anymore
- I can select one line in each field, is there also a command to restrict the total amount of hilited lines in a card to 1?
I do not want to have 1 line in 3 fields selected but max 1 in total.
Thanks alot!
Re: Filtering a string with a string
Posted: Tue Apr 25, 2017 4:48 pm
by Klaus
Hi Zood,
Zood wrote:Got it! I put "Auto Hilite" & "List behaviour" & "multi-line" & "non-contiguous" all to true and it worked.
It is as they say, when one problem is solved 3 more appear:
- I can't "unselect" a line anymore
Also check "togglehilites" for the field(s).
Zood wrote:- I can select one line in each field, is there also a command to restrict the total amount of hilited lines in a card to 1?
I do not want to have 1 line in 3 fields selected but max 1 in total.
No command for that, but just add something like this to all of your fields:
Code: Select all
on mouseup
set the hilitedline of fld "the other one 1" to 0
set the hilitedline of fld "the other one 2" to 0
## Your mouseup stuff here...
end mouseup
Best
Klaus
Re: Filtering a string with a string
Posted: Tue Apr 25, 2017 4:59 pm
by Zood
Great! thanks, it works as I wanted now.
I do keep getting an error when trying the "Strikeout" function.
It appears that the "put the hilitedLine of field "Container1" into tHighlitedLine1" does not output any data?
It gives me the following error:
executing at 5:48:15 PM
Type Object: object does not have this property
Object Delete
Line set the text style of line tHighlitedLine1 of field "Reserveringen1" to "strikeout"
Hint mouseUp
Any idea as to why it does not have that property? does that mean it is impossible for the lines to become "strikeout"?
When I delete the code-lines for the strikeout-part the lines do become the color i wanted to yet do not remain that color when I "refresh" the calendar?
Re: Filtering a string with a string
Posted: Tue Apr 25, 2017 5:44 pm
by Klaus
set the text style of line tHighlitedLine1 of field "Reserveringen1" to "strikeout"
ONE word: textstyle

Re: Filtering a string with a string
Posted: Tue Apr 25, 2017 8:57 pm
by Zood
Got it! thanks.
Another issue i have encountered:
Deleting a line in the original file
I have set my URL into a variable: CONTENTS
I have added a line to the URL and the line itself shows itself on a field in which i have put the contents of CONTENTS: So far so good!
Now I have a selected line (the highlited line) and i need to delete it from the original URL.
I tried running a loop through the URL to check whether the highlighted line equals a line in the URL then delete it but it keeps coming back.
This is what I have so far:
Code: Select all
put the hilitedline of field "CONTENTS" into tContents ## puts the line-number of the hilitedline into tContents
delete line tContents of field "CONTENTS" ## deletes the line which was highlighted from the selected field only, not from the URL
put line tContents of field "CONTENTS" into tContents3
repeat for each line tContents2 in url ("file:" & specialFolderPath("desktop") & "/CONTENTS.csv")
if tContents2 = tContents3 then
delete line tContents2 in url ("file:" & specialFolderPath("desktop") & "/CONTENTS.csv")
end if
end repeat
The code doesn't work but i can't understand why?
Thanks in advance!