Re: How do you convert a List back to a sequence ?

new topic     » goto parent     » topic index » view thread      » older message » newer message

----- Original Message -----
From: "Arthur Mashiatshidi" <arthurm at GOLDFIELDS.CO.ZA>
To: <EUPHORIA at LISTSERV.MUOHIO.EDU>
Sent: Wednesday, September 27, 2000 6:11 PM
Subject: How do you convert a List back to a sequence ?


> My Problem is converting a List-string back to a sequence: (# comments)
> Consider the following:
>
> MyList =3D (blaa....blaa...)
> MyDate =3D {2000,03,15}
> # to put this into  Mylist
>
> addItem(MyList, sprint(Mydate))  --# if you don't sprint Mydate, it wil=
l
> bomb out in certain conditions!!???
> # now I want to call MyList to use it to reference to a date in the
calendar
>
> MyNewDate =3D getItem(MyList, i)  # i is the number in of the item in t=
he
list
> # but alas, this is no longer {2000,03,15}
> # what is it? - I don't know, I can't seem to figure it out.
>
> How do you convert (MyList, i) back to MyDate sequence, so I can use
> subscripting to access the elements?
>
Hi Arthur,
the addItem() routine accepts a text sequence as the second parameter. Th=
is
means that every element in the sequence must be an atom, and each atom m=
ust
have a value from 0 - 255. In your example, the date's year is > 255 so i=
t
would not be stored correctly( I suspect it will be stored as character 2=
08
"=D0"). Also, the month and day values are non-printable characters so wo=
uld
also look weird when displayed.

This means that any item inserted by addItem must be a displayable string.
So in your case, you should format the date into a text string before usi=
ng
adItem().

For example...
---------------
sequence lDate

  if userDateStyle =3D "MDY"
  then
      lDate =3D sprintf("%02d%s%02s%s%04d", {theMonth, userDateSep, theDa=
y,
userDateSep, theYear})
  elsif userDateStyle =3D "DMY"
  then
      lDate =3D sprintf("%02d%s%02s%s%04d", {theDay, userDateSep, theMont=
h,
userDateSep, theYear})
  else  -- assume YMD format
      lDate =3D sprintf("%04d%s%02s%s%02d", {theYear, userDateSep, theMon=
th,
userDateSep, theDay})
  end if
  addItem(myList, lDate)

Then to get it back again, just convert the date portions (YMD) back into
numbers.

  lDate =3D getItem(myList, i)
  if userDateStyle =3D "MDY"
  then
      lDay =3D lDate[4 .. 5]
      lMonth =3D lDate[1 .. 2]
      lYear =3D lDate[7 .. 10]
  elsif userDateStyle =3D "DMY"
      lDay =3D lDate[1 .. 2]
      lMonth =3D lDate[4 .. 5]
      lYear =3D lDate[7 .. 10]
  else  -- assume YMD format
      lDay =3D lDate[9 .. 10]
      lMonth =3D lDate[6 .. 7]
      lYear =3D lDate[1 .. 4]
  end if
  lTemp    =3D value(lDay)
  theDay   =3D lTemp[2]  -- you may want to add some error checking if us=
ers
can change the list items.
  lTemp    =3D value(lMonth)
  theMonth =3D lTemp[2]
  lTemp    =3D value(lYear)
  theYear  =3D lTemp[2]


-----
cheers,
Derek.

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu