Ir diretamente para o conteúdo principal

Depuração de ficheiros de texto

'-------------------------------------------------------------------------------

' INÍCIO DO CABEÇALHO DE DEPURAÇÃO DO CÓDIGO PERSONALIZADO

'-------------------------------------------------------------------------------

Função TimeStamp

TimeStamp = FormatDateTime(Date(),0) + ' ' + FormatDateTime(Time(),3)

Fim da Função

bDebugMode = TRUE

bAppend = False

sCustomRuleName = 'DEBUG-'

sCustomRuleName = Replace(sCustomRuleName, ' ', '')

sTriggerAction = 'UserTimeCalibration'

sTriggerAction = Replace(sTriggerAction, ' ', '')

sDebugFile = sCustomRuleName + sTriggerAction + '.txt'

sDebugPath = 'C:\IndySoft\EventDebugger'

adTypeText = 2

adSaveCreateOverWrite = 2

adWriteLine = 1

adCRLF = -1

adReadAll = -1

Debug = CreateObject('ADODB.Stream')

Debug.Type = adTypeText

Debug.LineSeparator = adCRLF

Debug.Open

Se bDebugMode Então

oFileSystem = CreateObject('Scripting.FileSystemObject')

Se oFileSystem.FolderExists(sDebugPath) for falso Então

oFolderName = oFileSystem.CreateFolder(sDebugPath)

oFolderName = Nothing

Fim Se

sDebugFile = sDebugPath + sDebugFile

Se oFileSystem.FileExists(sDebugFile) Then

oFileName = oFileSystem.CreateTextFile(sDebugFile,True)

oFileName.Close

oFileName = Nothing

End If

oFileSystem = Nothing

If bAppend Then

Debug.LoadFromFile(sDebugFile)

Debug.ReadText(adReadAll)

Debug.SetEOS

End If

End if

Debug.WriteText(TimeStamp + ': Iniciando sessão de depuração para ' + sCustomRuleName + sTriggerAction,adWriteLine)

'-------------------------------------------------------------------------------

' FIM DO CABEÇALHO DE DEPURAÇÃO

'-------------------------------------------------------------------------------

Try

Debug.WriteText('START: ' + sCustomRuleName + ' : ' + sTriggerAction, adWriteLine)

'***********************************************************************

' TODO O SEU CÓDIGO VAI AQUI EM BAIXO

'***********************************************************************

'*****************************************************************************************************************************************************************************************************************************************************************************************

' FIM DE TODO O SEU CÓDIGO

'*************************************************************************************************************************************************************************************************************************************************************************************

' TODO O SEU CÓDIGO TERMINA AQUI

Debug.WriteText('FIM DO CÓDIGO',adWriteLine)

Debug.WriteText('FIM: ' + sCustomRuleName + ' : ' + sTriggerAction,adWriteLine)

Exceção

Debug.WriteText('Erro ocorrido' & LastExceptionMessage,adWriteLine)

ShowMessage('Este evento não foi concluído corretamente e, por isso, é inválido')

Fim

'-------------------------------------------------------------------------------

' INÍCIO DO RODAPÉ DE DEPURAÇÃO

'-------------------------------------------------------------------------------

Debug.WriteText(TimeStamp + ': A terminar sessão de depuração para ' + sCustomRuleName + sTriggerAction,adWriteLine)

If bDebugMode Then

Debug.SaveToFile(sDebugFile, adSaveCreateOverWrite)

End If

Debug.Close

Debug = Nothing

'-------------------------------------------------------------------------------

' FIM DO RODAPÉ DE DEBUG

'------------------------------------------------------------------------------- |