I want to write an OPL program to read the contacts file.
I'm programming directly on the N9210i.
From the OPL help (on ContactsOPX) it seems that one needs to sort the contacts in memory (by CoSortItems😊
and then access the "sorted" entries by index (by CoSortedItemsAt😊
The following is the program i'm trying.
let me point that just opening, counting and closing worked fine.
inside the loop, the CoSortedItemsAt: fails (marked with <===) and gives the msg:
"Error in CONTEX/CONTEX
Read Failed"
What's the problem here, and can you describe the way to go thru the contacts one-by-one,
and getting the fields (thru the template).
------ program -------------
INCLUDE "Contact.oxh"
PROC ContEx:
local totcon&, cdb$(255),i&, con&, ad&,mp&(3)
rem test existance
cdb$="c:\system\data\contacts.cdb"
if not exist(cdb$)
alert("Contacts DataBase NOT found",cdb$)
stop
endif
rem create mapping for sort
mp&(1)=3
mp&(2)=KUidCntFieldFamilyName&
mp&(3)=KUidCntFieldGivenName&
ad&=addr(mp&(1))
rem count items
CoOpenContactFile😞cdb$)
totcon&=COCountItems&:
rem sort file
CoSortItems😞ad&😉
rem loop on all contacts
i&=0
do
i&=i&+1
CoSortedItemsAt😞i&😉 <============
con&=CoItemId&:
CoReadItem😞con&😉
CoOpenItem😞con&😉
CoCloseItem:
until i&=totcon&
COCloseContactFile:
alert("Total of "+ gen$(totcon&,5) +" Contacts "😉
stop
ENDP
I didn't think it would be that difficult. Surely one of you with OPL experience had done it, I wish you couls share your experience.
It may not appear that difficult, but it's certainly something I've never used - and looking at the number of OPL based contacts apps on ER6, it not surprising theres not a huge depth of experience here.
Perhaps a posting here AND at the opl-dev SourceForge project may help?
What is SourceForge? Any link to it?
10x
NBP
http://opl-dev.sourceforge.net is the official homepage of the open source'd OPL.
Anything happening with OPL runtimes is likely to be available from there firstly. Unless Ewan makes a simultaneous announcement here of course.
Regards,
/Cruizer.
Re-posting source using CODE tag (hoping I'll be able to fix it...)
From the OPL help (on ContactsOPX) it seems that one needs to sort the contacts in memory (by CoSortItems😊
and then access the "sorted" entries by index (by CoSortedItemsAt😊
The following is the program i'm trying.
let me point that just opening, counting and closing worked fine.
inside the loop, the CoSortedItemsAt: fails (marked with <===) and gives the msg:
"Error in CONTEX/CONTEX
Read Failed"
What's the problem here, and can you describe the way to go thru the contacts one-by-one,
and getting the fields (thru the template).
INCLUDE "Contact.oxh"
PROC ContEx:
local totcon&, cdb$(255),i&, con&, ad&,mp&(3)
rem test existance
cdb$="c:\system\data\contacts.cdb"
if not exist(cdb$)
alert("Contacts DataBase NOT found",cdb$)
stop
endif
rem create mapping for sort
mp&(1)=3
mp&(2)=KUidCntFieldFamilyName&
mp&(3)=KUidCntFieldGivenName&
ad&=addr(mp&(1))
rem count items
CoOpenContactFile😞cdb$)
totcon&=COCountItems&:
rem sort file
CoSortItems😞ad&😉
rem loop on all contacts
i&=0
do
i&=i&+1
CoSortedItemsAt😞i&😉 : rem <============
con&=CoItemId&:
CoReadItem😞con&😉
CoOpenItem😞con&😉
CoCloseItem:
until i&=totcon&
COCloseContactFile:
alert("Total of "+ gen$(totcon&,5) +" Contacts "😉
stop
ENDP
It does not work!
Any help?
Found the solution: no need for buggish CoSortedItemsAt: (i&😉, just parse all contacts using CoReadItem: (con&😉, parse all fields of the item using COContactFieldArrayAt: (aIndex&😉 and stop when COContactFieldText$: has the desired value!