The stack I made is displaying categorized lines of text. I made a card to select the categories put them into a variable and populate a data grid form but the code for populating the data grid for My Categories does not work:
Here is the code for populating the form:
global gAllLines,gSelectedCategories,gMyCategories
on mouseUp
put empty into gAllLines
put fld "alllines" of cd "settings_files" of stack "settingsandfiles" into gAllLines
put empty into gMyCategories
repeat for each line i in gAllLines
if item 2 of i is among the items of gSelectedCategories then put i & cr after gMyCategories
end repeat
set the dgText of group "mycategories_compact" to gMyCategories
end mouseUp
The download link for the stack (best working so far, but still not 100% OK) is:
https://dl.dropboxusercontent.com/u/99863601/Data%20grid%20Form_All%20Lines%20Categories%20Selections3.zip
Please let me know how to fix it.
Thanks in advance.
keram
The problem is you have two different itemDelimiters. Your field "alllines" has tab delimited data while your gSelectedCategories has comma delimited. Try:
global gAllLines,gSelectedCategories,gMyCategories
on mouseUp
put empty into gAllLines
put fld "alllines" of cd "settings_files" of stack "settingsandfiles" into gAllLines
put empty into gMyCategories
replace comma with tab in gSelectedCategories
set the itemDelimiter to tab
repeat for each line i in gAllLines
if item 2 of i is among the items of gSelectedCategories then put i & cr after gMyCategories
end repeat
set the dgText of group "mycategories_compact" to gMyCategories
end mouseUp
Edit
I never use dgText so I'm not sure why buy this datagrid seems to not accept dgText["firstLineContainsColumnNames"] any more. So to me the logical solution is to use dgData:
global gAllLines,gSelectedCategories,gMyCategories
on mouseUp
set the dgData of group "mycategories_compact" to empty
put empty into gMyCategories
replace comma with tab in gSelectedCategories
set the itemDelimiter to tab
local tIndex = 1,tDataA
repeat for each line i in gAllLines
if item 2 of i is among the items of gSelectedCategories then
put item 1 of i into tDataA[tIndex]["Text"]
put item 2 of i into tDataA[tIndex]["Category"]
add 1 to tIndex
end if
end repeat
set the dgData of group "mycategories_compact" to tDataA
end mouseUp
I have not looked at your stack, but the handler works fine as far as it goes. That is, the global variable "gSelectedCategories" is loaded if one of the checkbox buttons has one of the words you are checking for in its name, What are you not seeing?
Craig Newman
Related
In a Data Grid table, I would like to change the backgroud color of a "selected" cell.
In the table, the user can select a cell in each row (I used a custom property that I increment each time the user click on the same row). I would like to highlight the selected cell, for instance by changing the bg color of it.
How can I do that ?
Thanks a lot.
I am fond of saying that I use data grids, but do not understand them.
A dataGrid is just a complex LC object, comprised of other LC objects, groups and behaviors. Each field is designated as, say: fld "Col 1 0002" (first column, second line)
So you could:
on mouseUp
set the opaque of fld "col 1 0002" to "true"
set the backColor of fld "col 1 0002" to "red"
end mouseUp
Now there may well be a "native" way of doing this, But I do not know it.
If I make a new DG and fill it with some tab and return delimited text, my handler turns the designated "cell" red.
I do notice that there was a spurious character after "end mouseUp" in my earlier post. I edited it out, but might this have caused your problem?
Do you have data in the "cell" you are interested in? This method will not work if it is empty. "No such object"? It may be that you need this as well:
on mouseUp
set the opaque of fld "col 2 0003" of grp "yourDG to "true"
set the backColor of fld "col 2 0003" of grp "yourDG" to "green"
end mouseUp
I found a way, thanks to the answer of dunbarx, and with adding the use of "the target".
on mouseUp
set the opaque of the target to "true"
set the backColor of the target to "green"
end mouseUp
I have a random word generation script that works perfectly. I also have a few single character-width fields, exactly the same amount of them as the longest possible word that can be generated. Below each field I have a line that would resemble an underscore. Each field has a unique id, numbered from one like so: "letter1", "letter2".... and so on. Likewise, each line has the id of "line1", "line2", and so on.
Now that I've set the stage, here is what I want to happen. On the opening of the card, I want all of the letter fields to hide as I will have them show individually outside this subroutine. I then want all of the lines to hide, and then only the amount of lines that are required for the random word should show again. (The same number as length(randomword) from left to right.) Now, the random word should be looped through and the first character should be put into the field "letter1", and the second into "letter2", and so on. The word will change each time the card is opened, so it is important that this is not bruteforced (which unfortunately, myself having two weeks experience with LiveCode, is the only thing I know concretely how to do).
Could someone with more experience do me a solid and provide the code I would need to do this, and the location I should put the code in? (the card? the letter fields? I really don't know at this point).
I am happy to provide further description if I have not been articulate about my problem.
Try this (my LiveCode is a bit rusty):
on openCard
//Put your word generation script here
put 0 into amtOfLines
put 0 into amtOfLetters
repeat until amtOfLines is 6 //Replace 6 with the amount of lines
add 1 to amtOfLines
put "line" & amtOfLines into x
set the visible of graphic x to false
end repeat
repeat until amtOfLetters is 6 //Replace 6 with the amount of fields
add 1 to amtOfLetters
put "letter" & amtOfLetters into x
set the visible of field x to false
end repeat
put 0 into amtOfLines
put 0 into amtOfLetters
repeat until amtOfLines is length(randomword)
add 1 to amtOfLines
put "line" & amtOfLines into x
set the visible of graphic x to true
end repeat
repeat until amtOfLetters is length(randomword)
add 1 to amtOfLetters
put "letter" & amtOfLetters into x
set the visible of field x to true
end repeat
put 0 into amtOfChars
repeat until amtOfChars is length(randomword)
add 1 to amtOfChars
put "letter" & amtOfChars into x
set the text of field x to char amtOfChars of randomword
end repeat
end openCard
This would go in the card script.
EDIT: Fixed some errors.
This would go into the card script:
on setup pRandomWord
put 6 into tNumObjs -- or however many fields there are
put length(pRandomWord) into tLen
repeat with x = 1 to tNumObjs
hide fld ("letter"&x)
if x <= tLen then
put char x of pRandomWord into fld ("letter"&x)
show grc ("line"&x)
else
hide grc ("line" & x)
end if
end repeat
end setup
When you want to use it, put the random word into a variable and call the setup handler like this:
setup randomWord
This does everything in a single repeat loop. The random word is passed to the setup handler in the parameter "pRandomWord".
I have two Scrolling field and one containing some text and another containing some words. eg. (s1:s2) separated by colon my objective is to find how many words in the second Scrolling are appearing in first Scrolling field. (eg: if s1 is appearing in first scrolling field then it shows s1,1 it means s1 appearing one time). While executing my code it's work but if my first scrolling field is empty it shows some text also some times it takes some words in the first field. (eg:\documentclass)this word is not in 2'nd field.
I am using the following code.
global ar
global sam
on mouseUp
--set the caseSensitive to true
put 0 into tmp
put empty into sam
put the field SRText into myArrayT
split myArrayT by CR
put the number of lines of (the keys of myArrayT) into myArrayl
repeat for each key j in myArrayT
put myArrayT[j] into k
split k by colon
put k[1] into searchStr1
put the field "MytextField" into sss
repeat for each word ass in sss
if ass contains searchStr1 then
add 1 to tmp
put ass & CR & CR after sam
put sam into ar
end if
end repeat
end repeat
answer sam
answer tmp
--answer sa
end mouseUP
on mouseDown
answer ar
put ar into ss
get ss
repeat for each word tWord in it
add 1 to wordCount[tword]
end repeat
combine wordCount by return and comma
answer wordCount
--put empty into sam
end mouseDown
You really should use quotes around field names. I promise you'll realise some day, that you have been shooting yourself in the foot all the time.
Don't use the in front of object references,
field "Field Name"
button "Field name"
but do use the in front of property references:
the number of lines of fld "Field Name"
the text of fld "Field Name"
the name of this stack
There really use no reason for your obsession with arrays. Stop using arrays when you don't need them! It just makes things overly complicated and slow.
I have modifed your mouseUp handler. I didn't look at your mouseDown handler. I believe your mouseUp handler should look like this:
on mouseUp
--set the caseSensitive to true
put 0 into tmp
put empty into sam
repeat for each line k in fld "SRText"
set the itemDel to colon
put item 1 of k into searchStr1
repeat for each word ass in field "MytextField"
if ass contains searchStr1 then
add 1 to tmp
put ass & colon & tmp & cr after sam
end if
end repeat
put 0 into tmp
end repeat
put sam
end mouseUp
The script above is based on your approach and I really don't understand why you would do it this way and what you would do with the result. The script below is probably much more efficient and it seems more useful to me.
on mouseUp
// I assume fld SRText contains a list similar to
// "abc:1" & cr & "bcd:2" & cr & "cde:1" & cr & "def:4"
put fld "SRText" into myData
split myData by cr and colon
put the keys of myData into myData
// myData is not an array!
repeat for each word myWord in fld "MytextField"
if myWord is among the lines of myData then
// use an array to store data, not to loop through
if myCounts[myWord] is empty then
put 1 into myCounts[myWord]
else
add 1 to myCounts[myWord]
end if
end if
end repeat
combine myCounts by cr and colon
put myCounts
end mouseUp
I need to do certain replacement after and before particular strings. Example: I need to "replace bad with good in field "MytextField"". But this replacement should be done after begin{document} and before end{document}. None of the word replace before begin {document} and after end{document}. How is this possible?.
if I use this code "replace bad with good in field "MytextField"" all the instants of bad should be replaced with good. I don't need to change the entire field.
This should work if your begin and end markers only appear once in the field...
put wordOffset("begin{document}",fld "MytextField") into tBegin
put wordOffset("end{document}",fld "MytextField") into tEnd
put replaceText(word tBegin to tEnd of fld "MytextField","bad","good") into word tBegin to tEnd of fld "MytextField"
If the markers appear several times you will need a repeat loop to step through each one.
Paul
Put this into a field: aa red aa red aa red aa red
Put this into a button
local latest
on mouseUp
put 0 into latest
startFinding fld 1,0
end mouseUp
on startFinding tText,tOffset
if the optionKey is down then exit to top --just in case...
put wordOffset("red",fld 1,tOffset) into latest
answer "Change word" && (latest + tOffset) && "?" with "Change" or "Continue"
If it = "change" then put "green" into word (latest + tOffset) of fld 1
add latest to tOffset
if tOffset < the number of words of fld 1 then startFinding fld 1,tOffset
end startFinding
I have a field "data" with Unicode text in it which displays properly. I want to copy a chunk of it and put it into another field called "someData".
I tried the following script in a button
on mouseUp
put word 2 of line 1 of the unicodeText of field "data" into t
set the unicodeText of field "someData" to t
end mouseUp
Non Unicode text displays fine in the field "someData" but Unicode text does not.
You could probably get away with UTF8 encoding then parsing then re-encoding
on mouseUp
put word 2 of line 1 of uniDecode(the unicodeText of field "data","UTF8") into t
set the unicodeText of field "someData" to uniEncode(t,"UTF8")
end mouseUp
on mouseUp
put unicode the unicodeText of word 2 of field "data" into field "someData"
end mouseUp
should work.
Marek
Here is another one-liner you can test:
set the unicodeText of field 2 to the unicodeText of word 2 of field 1
I am no expert in unicode, but there may be a clue in that LC treats most unicode stuff as properties. Because of this, one may set, say, the uniCodeText of a field:
set the unicodeText of fld 1 to "U+400"
But one cannot set that property, or any property, in a variable. Consider the following two handlers. It is assumed there exist two fields, "fld 1" and "fld 2".
on mouseUp
set the useUnicode to "true"
set the unicodeText of fld 1 to "U+400" -- an example
set the unicodeText of fld "f2" to the uniCodeText of fld 1
end mouseUp
on mouseUp
set the useUnicode to "true"
set the unicodeText of fld 1 to "U+400"
put fld 1 into temp
set the unicodeText of fld "f2" to temp
end mouseUp
The first works, the second does not. In your example, you try to put displayed uniCode into a variable. I don't think you can "put" that sort of thing. You have to set a property.
Now that said, check out the "put uniCode" command. This might get around the property thing. Write back if it does.
Craig Newman