16 de marzo de 2013

Leer tarjetas de contactos .VCF desde VFP

Una función para leer tarjetas de contactos .VCF desde Visual FoxPro enviada al foro de Foxite.com/forum por el hindú Rahul Moudgill.

ReadVcard(GETFILE("VCF"))
BROWSE

PROCEDURE ReadVcard
  LPARAMETERS cVcardFile

  IF !FILE(m.cVcardFile)
    RETURN .F.
  ENDIF

  #DEFINE clrf  CHR(13)+CHR(10)
  #DEFINE sTag   'BEGIN:VCARD'
  #DEFINE eTag   'END:VCARD'
  #DEFINE ver   'VERSION:'
  #DEFINE fn     'FN:'
  #DEFINE tel    'TEL;'
  #DEFINE email  'EMAIL;'
  SET MEMOWIDTH TO 254
  CREATE CURSOR vCard ;
    (;
    ID i,;
    NAME c(254),;
    FirstName c(100),;
    lastName c(100),;
    tg c(15),;
    TelType c(30),;
    contact c(50),;
    VERSION c(5),;
    TEXT m;
    )
  SCATTER MEMO NAME oVcardData BLANK


  LOCAL cvCardText,ntVcard,ix,cText,tText,jx,kx

  cvCardText=FILETOSTR(m.cVcardFile)
  ntVcard=OCCURS(sTag,M.cvCardText)

  FOR ix = 1 TO ntVcard
    SCATTER MEMO NAME oVcardData BLANK
    oVcardData.ID=m.ix
    cText=STREXTRACT(m.cvCardText,sTag,eTag,m.ix)
    oVcardData.TEXT=cText
    oVcardData.VERSION=STREXTRACT(m.cText,ver,clrf)
    oVcardData.NAME=STREXTRACT(m.cText,fn,clrf)
    oVcardData.FirstName=STREXTRACT(m.cText,[;],[;;;])
    oVcardData.LastName=STREXTRACT(m.cText,CHR(10)+[N:],[;])

    FOR kx = 1 TO MEMLINES(m.cText)
      FOR jx = 1 TO OCCURS(TEL,MLINE(m.cText,m.kx))
        tText=STREXTRACT(MLINE(m.cText,m.kx),TEL,[],m.jx)
        oVcardData.tg=TEL
        oVcardData.TelType=STREXTRACT(m.tText,"",":")
        oVcardData.Contact=STRTRAN(STREXTRACT(m.tText,":"),[-])
        INSERT INTO vCard ;
          FROM NAME oVcardData
      NEXT

      FOR jx = 1 TO OCCURS(EMAIL,MLINE(m.cText,m.kx))
        tText=STREXTRACT(MLINE(m.cText,m.kx),EMAIL,[],m.jx)
        oVcardData.tg=EMAIL
        oVcardData.TelType=STREXTRACT(m.tText,"",":")
        oVcardData.Contact=STRTRAN(STREXTRACT(m.tText,":"),[-])
        INSERT INTO vCard ;
          FROM NAME oVcardData
      NEXT
    NEXT

  NEXT
ENDPROC
Fuente: http://www.foxite.com/forum

No hay comentarios. :

Publicar un comentario