Array Question...

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
topcat888
Posts: 44
Joined: Sat Jan 02, 2010 8:10 pm

Array Question...

Post by topcat888 » Thu Jan 07, 2010 2:20 pm

Hi

I would like to say this:

If the the answer is not in the array (hand built) then write "No Answer" into field "outField"

I know the following is wrong but its what I want to say:

Code: Select all

if the theArray has the answer
   then
       put theArray[theIndex] into field "outField"
   else
      put "No Answer" into field "outField"
   end if

Could somebody show me the way..?

Thanks

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10317
Joined: Wed May 06, 2009 2:28 pm

Re: Array Question...

Post by dunbarx » Thu Jan 07, 2010 3:46 pm

I don't think you can access the data in them directly, but you can always change them from an array variable into a normal one and then check to see if a string is present:

put yourArray into temp
combine temp using yourDelimiter [and yourOtherDelimiter]
if yourString is in temp then put temp into field "outfield"

topcat888
Posts: 44
Joined: Sat Jan 02, 2010 8:10 pm

Re: Array Question...

Post by topcat888 » Thu Jan 07, 2010 8:46 pm

ok, thanks.

sturgis
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 1685
Joined: Sat Feb 28, 2009 11:49 pm

Re: Array Question...

Post by sturgis » Thu Jan 07, 2010 11:51 pm

If this is just a continuation of your other project with the combo boxes I think the following may do what you want.

Code: Select all

if theArray[theIndex] is empty then
put "No Answer." into field "outField"
else
put theArray[theIndex]
end if
topcat888 wrote:Hi

I would like to say this:

If the the answer is not in the array (hand built) then write "No Answer" into field "outField"

I know the following is wrong but its what I want to say:

Code: Select all

if the theArray has the answer
   then
       put theArray[theIndex] into field "outField"
   else
      put "No Answer" into field "outField"
   end if

Could somebody show me the way..?

Thanks


dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10317
Joined: Wed May 06, 2009 2:28 pm

Re: Array Question...

Post by dunbarx » Fri Jan 08, 2010 8:46 pm

Topcat, an array cannot be put into a field, or an answer dialog, or anything that displays it, until it has been converted back to a normal variable. Try it: make an array, and then put it into a field. You will see empty. Now combine the array using, say, a return. You will see the data. You can go back and forth, combining and splitting, all day.

Similarly, you cannot (I am sort of sure) determine if a string is in an array without first combining it. But that process is simple, and you will need to do so anyway in order to display its contents.

So, schematically:

put yourArray into temp
combine temp with space
if yourString is among the words of temp then put temp into field "outField"
else put "No Answer" into field "outField"

Post Reply