Here i am providing the function which creates Log files in QTP.
'===========================================
' Function: WriteLog
' description : Writes a message to a log file. File is created
' inside a Log folder of the current directory or on the Desktop
' Parameters :
'strCode is a code to prefix the message with.
'strMessage is the message of file.
'===========================================
Function WriteLog(strCode, strMessage)
Dim objFS
Dim objFS
Dim objFile
Dim objFolder
Dim strFileName
Set objFS = CreateObject("Scripting.FileSystemObject")
If Not objFS.FolderExists(objFS.GetAbsolutePathName(".") & "\log") Then
Set objFolder = objFS.CreateFolder(objFS.GetAbsolutePathName(".") & "\log")
End If
strFileName = objFS.GetAbsolutePathName(".") & "\log\" & year(date) & month(date) & day(date) & ".log"
Set objFile = objFS.OpenTextFile(strFileName, 8, True)
strFileName = objFS.GetAbsolutePathName(".") & "\log\" & year(date) & month(date) & day(date) & ".log"
Set objFile = objFS.OpenTextFile(strFileName, 8, True)
On Error Resume Next
objFile.Write Date & ", " & Time & ", " & strCode & ", " & strMessage & vbcrlf
' disable the on error statement
' disable the on error statement
On Error GoTo 0
objFile.Close
objFile.Close
Set objFS = Nothing
End Function
'Function Calling :
call WriteLog("Fail","Invalid User Credentials")
call WriteLog("Fail","Invalid User Credentials")
Output will be :
Nice good example,thank you for your code
ReplyDelete