Remove specific text from field
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller
-
- Posts: 78
- Joined: Wed Apr 10, 2013 9:08 pm
Remove specific text from field
Hi all.
Newbie here (been using app inventor for a year and now want to take a step up to multi platform capability)
Am trying to remove from a field a word depending on what is selected from an options button.
eg. user selects 'Yacht'.
After selection the word 'IPS' is removed from a field which is used to populate another option button on the page.
I would love for someone to point me to a tutorial for this type of thing. Am working thorough the App Academy at present.
Thanks in advance.
Newbie here (been using app inventor for a year and now want to take a step up to multi platform capability)
Am trying to remove from a field a word depending on what is selected from an options button.
eg. user selects 'Yacht'.
After selection the word 'IPS' is removed from a field which is used to populate another option button on the page.
I would love for someone to point me to a tutorial for this type of thing. Am working thorough the App Academy at present.
Thanks in advance.
Returning to try to learn livecode again.
But much greyer at the temples than the last time.
But much greyer at the temples than the last time.
-
- Posts: 78
- Joined: Wed Apr 10, 2013 9:08 pm
Re: Remove specific text from field
ok. Finding out how to do this slowly...
using this code and working through the various permutations. Sure i will get there soon! lol
case "Yacht"
get fld "FieldPropulsion"
if "ips" is in it then
put it into fld "FieldPropulsion"
get fld "FieldSelection"
put pItemName into it
put it into fld "FieldSelection"
using this code and working through the various permutations. Sure i will get there soon! lol
case "Yacht"
get fld "FieldPropulsion"
if "ips" is in it then
put it into fld "FieldPropulsion"
get fld "FieldSelection"
put pItemName into it
put it into fld "FieldSelection"
Returning to try to learn livecode again.
But much greyer at the temples than the last time.
But much greyer at the temples than the last time.
Re: Remove specific text from field
Hi.
Your code will run, but I am not sure what your intentions are. You mentioned that the user would remove a word from a field depending on a selection in an option button. There are a couple of ways to do this. You could, for example, map the selected word to the field word, perhaps by creating a list in a custom property:
IPS,firstWord
XYZ,secondWord
etc.
Then when the user selects the keyword, you can get the offset of that word in the list, and find the second item of the line it is in.
Then you can find the offset of that second item in the field text, and delete it. In fact, you could combine those two steps into one. You can also use the "find" command, with its "in field..." variant. Can you manage this? Or do I have some of it wrong? Not sure what the "populate another button..." part was all about.
Craig Newman
Your code will run, but I am not sure what your intentions are. You mentioned that the user would remove a word from a field depending on a selection in an option button. There are a couple of ways to do this. You could, for example, map the selected word to the field word, perhaps by creating a list in a custom property:
IPS,firstWord
XYZ,secondWord
etc.
Then when the user selects the keyword, you can get the offset of that word in the list, and find the second item of the line it is in.
Then you can find the offset of that second item in the field text, and delete it. In fact, you could combine those two steps into one. You can also use the "find" command, with its "in field..." variant. Can you manage this? Or do I have some of it wrong? Not sure what the "populate another button..." part was all about.
Craig Newman
-
- Posts: 78
- Joined: Wed Apr 10, 2013 9:08 pm
Re: Remove specific text from field
Hi Craig. Thanks for the input.
Found what i was looking for. In app inventor it would be the index of the list. I realised I would have to locate the position in the text file of the word I wanted then remove that line.
set the wholeMatches to true
put lineOffset ("IPS",it ) into tFoundLineNumber
if tFoundLineNumber > 0 then delete line tFoundLineNumber of it
put lineOffset("Jet",it) into tFoundLineNumber
if tFoundLineNumber >0 then delete line tFoundLineNumber of it
put lineOffset("Sterndrive",it) into tFoundLineNumber
if tFoundLineNumber >0 then delete line tFoundLineNumber of it
put it into text of button "propSelect"
This worked. Now I am playing with custom properties so I dont have the text in fields but in the custom properties of the card.
Problem now is that I cant seem to reference the information into the selection list. I am using
put vesselSetup[PropulsionType] of this card into tTempVal
get tTempVal
but I dont seem to get any values into the tTempVal. going back to the tutorials to understand variables and referencing them.
Enjoying every step of this new learning curve! lol
Found what i was looking for. In app inventor it would be the index of the list. I realised I would have to locate the position in the text file of the word I wanted then remove that line.
set the wholeMatches to true
put lineOffset ("IPS",it ) into tFoundLineNumber
if tFoundLineNumber > 0 then delete line tFoundLineNumber of it
put lineOffset("Jet",it) into tFoundLineNumber
if tFoundLineNumber >0 then delete line tFoundLineNumber of it
put lineOffset("Sterndrive",it) into tFoundLineNumber
if tFoundLineNumber >0 then delete line tFoundLineNumber of it
put it into text of button "propSelect"
This worked. Now I am playing with custom properties so I dont have the text in fields but in the custom properties of the card.
Problem now is that I cant seem to reference the information into the selection list. I am using
put vesselSetup[PropulsionType] of this card into tTempVal
get tTempVal
but I dont seem to get any values into the tTempVal. going back to the tutorials to understand variables and referencing them.
Enjoying every step of this new learning curve! lol
Returning to try to learn livecode again.
But much greyer at the temples than the last time.
But much greyer at the temples than the last time.
-
- Posts: 78
- Joined: Wed Apr 10, 2013 9:08 pm
Re: Remove specific text from field
Sorted. This step anyway.
Rather than referencing the custome properties I referenced the text of the button (which were from the custom properties). This changed the initial list to what I wanted.
Forwards with a step well learnt!
Code: Select all
get text of btn "propSelect"
set the wholeMatches to true
put lineOffset ("IPS",it ) into tFoundLineNumber
if tFoundLineNumber > 0 then delete line tFoundLineNumber of it
put lineOffset("Jet",it) into tFoundLineNumber
if tFoundLineNumber >0 then delete line tFoundLineNumber of it
put lineOffset("Sterndrive",it) into tFoundLineNumber
if tFoundLineNumber >0 then delete line tFoundLineNumber of it
set text of btn "propSelect" to it
Forwards with a step well learnt!
Returning to try to learn livecode again.
But much greyer at the temples than the last time.
But much greyer at the temples than the last time.
Re: Remove specific text from field
Hi.
Properties, and especially custom properties, have to be addressed with the word "the". So your:
put vesselSetup[PropulsionType] of this card into tTempVal
should be:
put the vesselSetup[PropulsionType] of this card into tTempVal
Variables can be addressed directly:
put yourVariable into myVariable
And though there is nothing wrong with doing so, do you need an array variable as opposed to an ordinary one when using the property?
Craig
Properties, and especially custom properties, have to be addressed with the word "the". So your:
put vesselSetup[PropulsionType] of this card into tTempVal
should be:
put the vesselSetup[PropulsionType] of this card into tTempVal
Variables can be addressed directly:
put yourVariable into myVariable
And though there is nothing wrong with doing so, do you need an array variable as opposed to an ordinary one when using the property?
Craig
-
- Posts: 78
- Joined: Wed Apr 10, 2013 9:08 pm
Re: Remove specific text from field
Hi again.
Well that is a newbie mistake. First of many I reckon.
Still getting to grips with understanding variables. Does not require to be an array. Just seemed to look nicer. lol.
If I didn't use an array then I am guessing lineOffset would need to be changed to itemOffset (or something like that. have not looked further so its a guess)
Brian
Well that is a newbie mistake. First of many I reckon.
Still getting to grips with understanding variables. Does not require to be an array. Just seemed to look nicer. lol.
If I didn't use an array then I am guessing lineOffset would need to be changed to itemOffset (or something like that. have not looked further so its a guess)
Brian
Returning to try to learn livecode again.
But much greyer at the temples than the last time.
But much greyer at the temples than the last time.
Re: Remove specific text from field
Hmmm.
I think you are reading the dictionary syntax as if it was LC syntax.
This harkens back to the days of Hypercard, where the formal syntax of a command, say, had "tags" that denoted options or optional parameters. I think you saw the "[" in the "lineOffset" definition and thought it had to be in array form. Those brackets indicate optional parameters, in this case, [lines to skip]. There are a handful of these, options within a parameter being "|" for example (see "put" for a simple instance).
The offset functions all return ordinary strings. But be careful, some LC gadgets do either require or create arrays.
Hey, anyone else run into this? It makes sense that TribbleHunter made that leap.
Craig Newman
I think you are reading the dictionary syntax as if it was LC syntax.
This harkens back to the days of Hypercard, where the formal syntax of a command, say, had "tags" that denoted options or optional parameters. I think you saw the "[" in the "lineOffset" definition and thought it had to be in array form. Those brackets indicate optional parameters, in this case, [lines to skip]. There are a handful of these, options within a parameter being "|" for example (see "put" for a simple instance).
The offset functions all return ordinary strings. But be careful, some LC gadgets do either require or create arrays.
Hey, anyone else run into this? It makes sense that TribbleHunter made that leap.
Craig Newman