Page 1 of 1
Using variables
Posted: Thu Aug 05, 2010 9:11 pm
by Andycal
Sorry for the vague subject, I really don't know how to couch this question as I think it's a fundamental misunderstanding on my part...
I did this:
put the selectedchunk into tChunk
And tChunk now equals "char 1 to 4 of field 1"
Which is brilliant. But if I then do :
put "hello" into tChunk
It obviously does what I told it, which isn't what I want, I actually want it to
put "hello" into char 1 to 4 of field 1
So what fundamental bit of the language am I missing here?
Re: Using variables
Posted: Thu Aug 05, 2010 10:08 pm
by mwieder
As always, there are a number of ways to do this.
The most straightforward, given your example, is probably
Code: Select all
do "put hello into" && the selectedChunk
But that's not a very generic solution. And the "do" command is pretty slow.
If the text you want is already in the clipboard then the simplest solution is probably to select the chunk and say
Re: Using variables
Posted: Thu Aug 05, 2010 11:15 pm
by Curry
By putting word 2 and word 4 of the selectedchunk into variables, you can do whatever you like.
Re: Using variables
Posted: Thu Aug 05, 2010 11:21 pm
by Curry
Or an easier way for this particular situation:
Re: Using variables
Posted: Thu Aug 05, 2010 11:24 pm
by bn
Hi Andy,
put the selectedchunk into tChunk
put "hello" into tChunk
As you can see the syntax is in both cases the same, Rev does not know that in the second case you dont want to put a value into the variable tChunk but into the
value of the variable tChunk. I think this is the missing piece in your concept of variables. Once you operate at the level of putting something into a container (variable) and then at the level of putting something into the value of the container.
Mark Wieder's solution forces Rev to evaluate the whole expression (do) which does what you want but is slow as Mark pointed out.
Another way to do this would be
Code: Select all
put the selectedChunk into tChunk
put word 2 of tChunk into tStart
put word 4 of tChunk into tEnd
put word -1 of tChunk into tSource -- field # or name
if tChunk <> "" then -- something has to be selected
put "hello" into char tStart to tEnd of field tSource
end if
regards
Bernd
Re: Using variables
Posted: Fri Aug 06, 2010 7:31 am
by Andycal
Thanks for all your help guys. I actually did what Bernd suggested in my script before I asked the question, but I wondered if there was a more elegant or less verbose way of doing it.
I also tried "put xxx into the selection" and that didn't work for some reason (although that was last week and I may have got it wrong).
Anyway, just happy to know I'm not a dunderhead!