I am trying to write a script to gather Name, address, etc… in a text file.
But my handler is not working sometimes get a message “script doesn’t understand message”, sometimes it works.
Why?
set the iDay to day of the (current date) as integer
if iDay < 10 then set iDay to "0" & iDay as text
set the iMonth to month of the (current date) as text
set CaminhoArquivo to (path to desktop as text) & "Teste" & iDay & "_" & iMonth & ".txt"
-- Aqui voc� pergunta a raz�o social:
set razaopergunta to Texto_Novo("Qual � a raz�o social", 53, "Raz�oSocial:", "", " ")
get razaopergunta
set TextoFinal to ""
set TextoFinal to TextoFinal & razaopergunta
--Aqui voc� pergunta o endere�o:
set enderecopergunta to Texto_Novo("Qual � o endere�o", 49, "Endere�o:", "", " ")
get enderecopergunta
--set TextoFinal to ""
set TextoFinal to TextoFinal & enderecopergunta
my write_to_file(TextoFinal, CaminhoArquivo)
on Texto_Novo(pergunta, MeuLimiteCaracteres, Limitador1, Limitador2, caracterespaco)
set pergunta to display dialog pergunta default answer "Escreva aqui a resposta" buttons "Ok" default button "Ok"
set meuTexto to Limitador1 & text returned of pergunta
set Limitador1 to offset of Limitador1 in meuTexto
set Limitador2 to offset of Limitador2 in meuTexto
set Texto_Novo to (characters Limitador1 thru (Limitador2 - 1) of meuTexto) as string
set myCount to the count of Texto_Novo
set diferenca to MeuLimiteCaracteres - myCount
if myCount is equal to MeuLimiteCaracteres then
return Texto_Novo
end if
if myCount is greater than MeuLimiteCaracteres then
set diferenca to myCount - MeuLimiteCaracteres
repeat diferenca times
set Texto_Novo to characters 1 thru -(Limitador1 + 1) of Texto_Novo as string
end repeat
return Texto_Novo
end if
if myCount is not greater than MeuLimiteCaracteres then
repeat diferenca times
set Texto_Novo to Texto_Novo & caracterespaco
end repeat
return Texto_Novo
end if
end Texto_Novo
on write_to_file(this_data, target_file)
try
set the target_file to the target_file as text
set the open_target_file to open for access file target_file with write permission
write this_data to the open_target_file starting at eof
close access the open_target_file
on error
try
close access file target_file
end try
end try
end write_to_file
Thanks!
Bernardo
Rio de Janeiro - Brazil