Economy-x-Talk - Sample Scripts
Csv2vcf Conversion
This script by Paul Foraker, largely based on the work by Harry Whitfield, converts csv address files to the vcf format. The vcf format is used by e-mail applications to exchange personal data. Of course, the csv file needs a particular structure, which you have to figure out yourself, for now.
on csvToVcf
put NewFileName("Save vCard file as:","Addresses.vcf") into it
if it is empty then exit csvToVcf
put it into fileName
open file fileName
write vCard() to file fileName
close file fileName
-- get ChangeFileType(fileName, "TEXT", "R*ch")
end csvToVcf
-- version by Harry Whitfield as of 030210 ; mod by Paul Foraker 20030725
function newfileName prompt,suggestion
ask file prompt with suggestion
if it is empty then exit to HyperCard
return it
end newFileName
function vCard
answer file "Where is the .csv file?" of type "TEXT"
if it is empty then exit to HyperCard
put it into fName
open file fName
read from file fName until EOF
close file fName
put it into theList
put empty into theVCards
put return & numToChar(10) into endOfLine
get the seconds
convert it to dateitems
put item 1 of it into year
put item 2 of it into month
put item 3 of it into day
if length(month) = 1 then put "0" before month
if length(day) = 1 then put "0" before day
put year & month & day into theDate
delete line 1 of theList -- headers
repeat with i = 1 to the number of lines in theList
set cursor to busy
put line i of theList into thisOne
put item 1 of thisOne into theName
put item 3 of thisOne into firstName
put item 4 of thisOne into lastName
put item 16 of thisOne into org
put item 6 of thisOne into theStreet
put empty into theStreet2
-- if theStreet2 is not "" then
-- put theStreet & "=0D=0A" & theStreet2 into theStreet
-- end if
put item 7 of thisOne into theCity
put item 8 of thisOne into theState
put item 10 of thisOne into theZip
put item 11 of thisOne into homeTel
-- nickname,name,first,last,email,address,city,state,country,zip,phone,fax,
-- 1-----------2------3-----4---5-----6---------7-----8--
-- mobile,web,title,company,address2,city2,state2,country2,zip2,phone2,fax2,
-- 13-----14----15---16------17---------18----19-----20---------
-- mobile2,web2,otheremail,otherphone,otherweb,note,picture
---24-------25----26----------27-----------28---------29---30
put item 22 of thisOne into workTel
put item 12 of thisOne into faxTel
put item 13 of thisOne into mobileTel
put item 5 of thisOne into Email
put item 14 of thisOne into WWW
put item 29 of thisOne into theNotes
put the number of chars in theNotes into n
repeat with i = n down to 1 -- 1 to n
get char i of theNotes
if it is return then
put "=0D=0A" into char i of theNotes
end if
end repeat
put empty into Category
put "BEGIN:VCARD" & endOfLine after theVCards
put "VERSION:2.1" & endOfLine after theVCards
put "FN:" & theName & endOfLine after theVCards
put "N:" & lastName & ";" & firstName & endOfLine after theVCards
put "ADR;HOME;QUOTED-PRINTABLE:;;" & theStreet & ";" & theCity & ";" & theState & ";" & theZip & endOfLine after theVCards
put "LABEL;QUOTED-PRINTABLE:" & theStreet & "=0D=0A" & theCity & "=0D=0A" & theState && theZip & endOfLine after theVCards
if homeTel is not empty then
put "TEL;HOME:" & homeTel & endOfLine after theVCards
end if
if workTel is not empty then
put "TEL;WORK:" & workTel & endOfLine after theVCards
end if
if faxTel is not empty then
put "TEL;FAX;type=WORK:" & faxTel & endOfLine after theVCards
end if
if mobileTel is not empty then
put "TEL;CELL:" & mobileTel & endOfLine after theVCards
end if
if Email is not empty then
put "EMAIL;type=WORK;type=pref:" & Email & endOfLine after theVCards
end if
if org is not empty then
put "ORG:" & org & endOfLine after theVCards
end if
if theNotes is not empty then
put "NOTE;QUOTED-PRINTABLE:=0D=0A[Comments]=0D=0A" & theNotes & endOfLine after theVCards
end if
if WWW is not empty then
put "URL:" & WWW & endOfLine after theVCards
end if
put "REV:" & theDate & endOfLine after theVCards
if Category is not empty then
put "X-Palm-Category1:" & Category & endOfLine after theVCards
end if
put "END:VCARD" & endOfLine after theVCards
end repeat
return theVCards
end vCard
Keep this extensive resource of tutorials and samples on-line! Support RunRev.info!
| Yes, this script is useful. I make a donation and choose freely how much I want to donate on-line (PayPal). Click here if you want to make a donation in dollars. | This script has not (completely) solved my problem and I want Economy-x-Talk to take care of it. Let me contact you. |
Copyright©2002-2008 by Mark Schonewille, Nijmegen, the Netherlands. This web site is in no way affiliated with Runtime Revolution Ltd., but we do recommend the Revolution development platform.