Page 1 of 1
Putting Value Of Text Field Into Variable
Posted: Tue Sep 23, 2008 2:55 pm
by warrenk
Probably a stupid question but I am having trouble finding the answer to this...
I can play a variable into a text field...
put variable1 into field "Text Field 1"
Now how can I place the valur of a text field into a variable?
Thanks!
Warren
Posted: Tue Sep 23, 2008 3:11 pm
by SparkOut
Just reverse it!
Code: Select all
put field "Text Field 1" into variable1
should be fine most of the time. There may be occasions where you need to specify "the text of" the field, as in:
Code: Select all
put the text of field "Text Field 1" into variable1
If that doesn't work simply, then are you getting any error messages which can shed light on what's going wrong for you? The only thing I can guess why that wouldn't work straight away is that you have not declared the variable name before you try to put something into it, and you have strict compilation mode set in the preferences.
Posted: Tue Sep 23, 2008 3:38 pm
by warrenk
Thanks SparkOut! I new this would be something simple. Only my 3rd day of using the software. Love it...but I know I have a long way to go.
Thanks again!
Warren
Posted: Tue Sep 23, 2008 9:19 pm
by bangkok
SparkOut wrote:Just reverse it!
There may be occasions where you need to specify "the text of" the field,
Could you elaborate ?
What are those occasions ?
Posted: Thu Sep 25, 2008 10:41 am
by SparkOut
Well in theory, I believe the two should be equivalent, so hopefully there wouldn't be a case that it causes a problem.
I remember one time in version 2.8.1 on Windows XP that I had a problem script and changing to refer to "the text of field" instead of just "field" made things run - but that may or may not have been the actual cure, and quite probably the script itself was damaged and simply retyping the line made it work. (I had that quite a few times with the 2.8.1 script editor - copying a working handler and pasting it into another card or stack would not work, yet if I pasted the handler into notepad, and then copied and pasted line by line into the new handler's destination it worked fine.)
I think (and I stand to be corrected) the syntax is like that so as to distinguish between the htmlText or the unicodeText or rtfText of a field and just the "text" of a field without any formatting. Putting 'field' should be the equivalent of putting 'the text of field' which is a handy shorthand in the case of extracting the unformatted text value of a field, but worth remembering as a distinction from the formatted text properties.
Posted: Thu Sep 25, 2008 11:52 am
by Mark
Hi SparkOut and Bangkok,
These cases occur in particular when the name of a field itself is stored in a variable (or any other container). For example:
put the long id of fld 1 into myFld
put myFld into myFldID --> still long ID
put the text of myFld into myText --> text
It also happens when you refer to a field using the me keyword and you want to do something special. Let's say that a field contains the name of another field:
put the long id of me --> long id of the field containing the name
put the long id of (the text of me) --> long id of fld <the name>
I admit these examples are a bit silly, but there are more cases where "me" is parsed as a reference to a field rather than as text (or the opposite). I'm sure you will run into them at some point.
Best,
Mark
Posted: Thu Sep 25, 2008 12:49 pm
by SparkOut
duh! thanks Mark. Of course I understood that, but forgot about it. Although in a similar way, you can also evaluate the contents of variables as fields by enclosing in parentheses:
put "Some text" into field "Field1"
put "Field1" into myField1
put myField1 into field "Field2" --> Field2 contains "Field1" as text
put field (myField1) into field "Field2" --> Field2 contains "Some text" as taken from the contents of the evaluated value of myField1
Anyway, that's what I was trying to intimate in the original comment - that Rev is a rich and very flexible language and there are many ways to achieve what's needed, with plenty of shorthands to make things simple and efficient - but when a finer degree of specification is required, there are usually options to cater for it.