Author Topic: How do lists work?  (Read 3369 times)

Gallante

  • Newbie
  • *
  • Posts: 2
How do lists work?
« on: October 15, 2011, 07:34:14 AM »
I'm stuck on something really basic and need some help.

In several places in the help it mentions lists that store data but I just don't understand how to put data into a list or to get it out of one.
if i want a list of fruit with apples,oranges,pears then how could i make such a list, and then how could i fetch a fruit from it?

Malkom

  • Administrator
  • Sr. Member
  • *****
  • Posts: 287
Re: How do lists work?
« Reply #1 on: October 15, 2011, 03:59:17 PM »
I'm stuck on something really basic and need some help.

In several places in the help it mentions lists that store data but I just don't understand how to put data into a list or to get it out of one.
if i want a list of fruit with apples,oranges,pears then how could i make such a list, and then how could i fetch a fruit from it?

Hi Gallante

Here are the basics of lists.

All variables in HyperNext are text (strings) but it it has some commands for treating variable as lists where the items within the list are delimited by return  characters.

So for instance to use your example of fruit. This places those items in a list:

Code: [Select]
Local list

@ ensure list only has apples in it
Put 'apples' into list

Put 'oranges' after list

Put 'pears' after list



To see how many items are in a list use the LinesFN function

Code: [Select]
Put LinesFN(list) into field 1


To get an item from a list use the following form of PUT command

Code: [Select]
@ get line 2 - oranges
Put line 2 of list into field 1


To put all the items in a list into a field use:-

Code: [Select]
Local list,count,i

Put LinesFN(list) into count

If count>0 then
   For i=1 to count
      Put Line i of list after field 1
   endfor
endif



Note, if the items in your list have return characters within them then either use arrays or convert the return characters to another character.

Malkom









I am sorry but I do not have time to answer questions by PM or email.
If you post your questions in this forum then it might help others.

Gallante

  • Newbie
  • *
  • Posts: 2
Re: How do lists work?
« Reply #2 on: October 15, 2011, 08:12:26 PM »
Hi Malkom,

Thank you for the quick answer that helps a lot.

It has occured to me that items might be paragraphs of text containing returns so how should I do it and which alternate character should I use?
 
Gallante

Malkom

  • Administrator
  • Sr. Member
  • *****
  • Posts: 287
Re: How do lists work?
« Reply #3 on: October 16, 2011, 04:32:39 PM »
It has occured to me that items might be paragraphs of text containing returns so how should I do it and which alternate character should I use?

Use the ReplaceAll command as in:-

Code: [Select]
ReplaceAll word1 with word2 in source


Decide which character will not be used in your items, for example a TAB character has the value 9.

The table here can help one decide:-

http://www.asciitable.com/


Code: [Select]
Local word1,word2,item

@ return char
Put ChrFN(13) into word1

@ tab char
Put ChrFN(9) into word2

ReplaceAll word1 with word2 in item




I am sorry but I do not have time to answer questions by PM or email.
If you post your questions in this forum then it might help others.