Create log file in QTP

Function LogintoFile(strCode, strMessage) 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) On Error Resume Next objFile.Write Date & ", " & Time & ", " & strCode & ", " & strMessage & vbcrlf ' disable the on error statement On Error GoTo 0 objFile.Close Set objFS = Nothing End Function 'Function Calling : call LogintoFile("Fail","Invalid User Credentials")