A solução que venho apresentar se adequa ao uso com Clipper para DOS pelo simples fato de fazer uso de recursos do sistema operacional aos quais o mesmo não tem acesso direto.
A integração é feita através de automação tradicional via arquivos de lote e scripts com código que depois pode ser portado para linguagens 32 bits que tenham melhor suporte a automação OLE.
Vou apresentar 3 scripts que fazem uso desta ponte para ter acesso ao Outlook 2003.
Sei, sei, já faço automação com meu Outlook para enviar emails e blablabla.
Não foi esta a minha intenção e sim permitir outros recursos.
Vamos ao primeiro:
Este conjunto irá permitir que seu aplicativo envie dados e acrescente um registro de contato no seu Outlook.
Código CONTATO.VBS:
Código: Selecionar todos
'************************************************
' Arquivo: Contato.vbs
' Autor: Jose Carlos da Rocha
'
' Adiciona um novo contato no Outlook.
'************************************************
Set colNamedArguments = WScript.Arguments.Named
strFirstName = colNamedArguments.Item("FirstName")
strLastName = colNamedArguments.Item("LastName")
strTelephoneNumber = colNamedArguments.Item("BusinessTelephoneNumber")
strEmail1Address = colNamedArguments.Item("Email1Address")
strCompanyName = colNamedArguments.Item("CompanyName")
strJobTitle = colNamedArguments.Item("JobTitle")
Set objOutl = CreateObject("Outlook.Application")
Set objContact = objOutl.CreateItem(2) 'olContactItem
objContact.FirstName = strFirstName
objContact.LastName = strLastName
objContact.BusinessTelephoneNumber = strTelephoneNumber
objContact.Email1Address = strEmail1Address
objContact.CompanyName = strCompanyName
objContact.JobTitle = strJobTitle
objContact.Save
objContact.Display
Código: Selecionar todos
wscript contato.vbs /FirstName:Jose /LastName:Rocha /BusinessTelephoneNumber:3534-3099 /Email1Address:"Rua Dr Mario Mauro Ramos Mattoso 50" /CompanyName:5volution.COM /JobTitle:"Analista de Sistemas"
Código TAREFA.VBS:
Código: Selecionar todos
'************************************************
' Arquivo: Tarefa.vbs
' Autor: Jose Carlos da Rocha
'
' Adiciona uma nova tarefa no Outlook.
'************************************************
Set colNamedArguments = WScript.Arguments.Named
If Not colNamedArguments.Exists("tarefa") Then
Wscript.Echo "Uso: /Tarefa:<tarefa> é requerido."
Wscript.Quit
end if
If Not colNamedArguments.Exists("data") Then
Wscript.Echo "Uso: /Data:<data> é requerido."
Wscript.Quit
end if
strTarefa = colNamedArguments.Item("Tarefa")
strData = colNamedArguments.Item("Data")
'Wscript.Echo "Server Name: " & strTarefa
'Wscript.Echo "Packet Size: " & strData
Set objOutl = CreateObject("Outlook.Application")
Set objTask = objOutl.CreateItem(3)
objTask.Subject = strTarefa
objTask.DueDate = strData
objTask.Save
objTask.Display
Código: Selecionar todos
wscript tarefa.vbs /Tarefa:"Avisar ao Rochinha que funciona legal." /Data:15/02/2010
Código .VBS:
Código: Selecionar todos
'************************************************
' Arquivo: Agenda.vbs
' Autor: Jose Carlos da Rocha
'
' Adiciona um novo agendamento no Outlook.
'************************************************
Set colNamedArguments = WScript.Arguments.Named
strStart = colNamedArguments.Item("Start")
strAllDayEvent = colNamedArguments.Item("AllDayEvent")
strSubject = colNamedArguments.Item("Subject")
strBody = colNamedArguments.Item("Body")
strLocation = colNamedArguments.Item("Location")
strReminderMinutesBeforeStart = colNamedArguments.Item("ReminderMinutesBeforeStart")
strReminderSet = colNamedArguments.Item("ReminderSet")
Set objOutlook = CreateObject("Outlook.Application")
Set objAppointment = objOutlook.CreateItem(1)
objAppointment.Start = strStart
objAppointment.AllDayEvent = strAllDayEvent
objAppointment.Subject = strSubject
objAppointment.Body = strBody
objAppointment.Location = strLocation
objAppointment.ReminderMinutesBeforeStart = strReminderMinutesBeforeStart
objAppointment.ReminderSet = strReminderSet
objAppointment.Save
objAppointment.Display
Código: Selecionar todos
wscript agenda.vbs /Start:25/12/2009 /AllDayEvent:True /Subject:"Inventario Anual" /Body:"Inventario Anual Referente a Periodo 2009." /Location:"ABCD das Espumas" /ReminderMinutesBeforeStart:15 /ReminderSet:True
Dicas finais:
O trecho abaixo ilustra como passar parâmetros para os scripts de forma que os mesmos sejam nomeados:
Código: Selecionar todos
Set colNamedArguments = WScript.Arguments.Named
Código: Selecionar todos
strFirstName = colNamedArguments.Item("FirstName")
No trecho abaixo ilustro como testar se o parâmetro foi passado:
Código: Selecionar todos
If Not colNamedArguments.Exists("tarefa") Then
Wscript.Echo "Uso: /Tarefa:<tarefa> é requerido."
Wscript.Quit
end if
