Using variables

LiveCode is the premier environment for creating multi-platform solutions for all major operating systems - Windows, Mac OS X, Linux, the Web, Server environments and Mobile platforms. Brand new to LiveCode? Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
Andycal
Posts: 144
Joined: Mon Apr 10, 2006 3:04 pm

Using variables

Post by Andycal » Thu Aug 05, 2010 9:11 pm

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?

mwieder
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3581
Joined: Mon Jan 22, 2007 7:36 am
Contact:

Re: Using variables

Post by mwieder » Thu Aug 05, 2010 10:08 pm

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

Code: Select all

paste

Curry
Posts: 111
Joined: Mon Oct 15, 2007 11:34 pm
Contact:

Re: Using variables

Post by Curry » Thu Aug 05, 2010 11:15 pm

By putting word 2 and word 4 of the selectedchunk into variables, you can do whatever you like.
Best wishes,

Curry Kenworthy

LiveCode Development, Training & Consulting
http://livecodeconsulting.com/

WordLib: Conquer MS Word & OpenOffice
SpreadLib: "Excel-lent" spreadsheet import/export
http://livecodeaddons.com/

Curry
Posts: 111
Joined: Mon Oct 15, 2007 11:34 pm
Contact:

Re: Using variables

Post by Curry » Thu Aug 05, 2010 11:21 pm

Or an easier way for this particular situation:

Code: Select all

put "hello" into the selection
Best wishes,

Curry Kenworthy

LiveCode Development, Training & Consulting
http://livecodeconsulting.com/

WordLib: Conquer MS Word & OpenOffice
SpreadLib: "Excel-lent" spreadsheet import/export
http://livecodeaddons.com/

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 4172
Joined: Sun Jan 07, 2007 9:12 pm

Re: Using variables

Post by bn » Thu Aug 05, 2010 11:24 pm

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

Andycal
Posts: 144
Joined: Mon Apr 10, 2006 3:04 pm

Re: Using variables

Post by Andycal » Fri Aug 06, 2010 7:31 am

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!

Post Reply