Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Function written in Func library is not returning values but works in same script
#1
Not Solved
Hi,

Below function when put in a function library is not returning values, while the same copied to same script works.

Note:Script is associated with the library & other sub procedures in the same library called by the same script are working fine.

Below is the code in the script:
Code:
Set myxl=nothing
Set myxl=Createobject("Excel.Application")
myxl.Application.Visible=True
User="sfp"
'Create Link object
Set weblnk=nothing
Set weblnk=description.Create
weblnk("micclass").value="Link"
Set objAlllinkobj=Nothing
Set objAlllinkobj=Browser("title:=.*","micclass:=Browser").Page("title:=.*","micclass:=Page").ChildObjects(weblnk)

''Create excel file to write data
Environment.Value("Alllinksfile")= "C:\Linkcheck\" & User & ".xlsx"
filepath=Environment.Value("Alllinksfile")
Set fso=Createobject("Scripting.FileSystemObject")
If fso.FileExists(filepath) Then
    fso.DeleteFile filepath
End If

Set xlbok=myxl.Workbooks.Add
Set mysheet=nothing
Set mysheet=myxl.Worksheets("Sheet1")
mysheet.cells(1,1)="Link"
mysheet.cells(1,2)="Status"
mysheet.cells(1,3)="Error Code"
mysheet.cells(1,4)="URL"

For a=0 to objAlllinkobj.count-1
roc=mysheet.usedrange.rows.count

url = objAlllinkObj(a).getroproperty("href")
'msgbox url
nam=objAlllinkObj(a).getroproperty("name")

'URL status
Call Geturlstatus (url)
Next

*************************************
Function  Geturlstatus(url)
On Error Resume Next
     'Call ClearBrowserCache()
     Set objhttp = nothing
     Set objhttp= CreateObject("Microsoft.XMLHTTP")  ' Create an xmlhttp object
     objhttp.open "GET", url, False     ' Opens the connection to the remote server
     objhttp.Send
     pagestatus = objhttp.status
    

     If pagestatus >= "200" or pagestatus <= "206" Then
         mysheet.cells(roc+1,1)=nam
         mysheet.cells(roc+1,2)="Success"
         mysheet.cells(roc+1,3)=pagestatus
         mysheet.cells(roc+1,4)=url
                     'geturlstatus = 0

     elseif pagestatus >= "302" or pagestatus <= "307" Then
          mysheet.cells(roc+1,1)=nam
         mysheet.cells(roc+1,2)="Redirection"
         mysheet.cells(roc+1,3)=pagestatus
         mysheet.cells(roc+1,4)=url
             'geturlstatus = 0

      elseif pagestatus >= "400" or pagestatus <= "423" Then
         mysheet.cells(roc+1,1)=nam
         mysheet.cells(roc+1,2)="Client Error"
         mysheet.cells(roc+1,3)=pagestatus
         mysheet.cells(roc+1,4)=url
            'geturlstatus = 0

  elseif pagestatus >= "500" or pagestatus <= "505" Then
         mysheet.cells(roc+1,1)=nam
         mysheet.cells(roc+1,2)="Server Error"
         mysheet.cells(roc+1,3)=pagestatus
         mysheet.cells(roc+1,4)=url
               ' geturlstatus = 1
    
     End If
     Set objhttp = nothing
     End Function
**************************************************
Reply
#2
Not Solved
------------------------------------------------------------
Hi Selvam,
Thanks for the reply!
Below code isn't working still and throwing following errors-
Scenario1:
1.Access Denied: objhttp.send
2.Object required: 'mysheet'
Function file: C:\CCAMSauto\Links.qfl
Line (12): " mysheet.cells(roc+1,1)=nam".
Scenario2: When i copy the same function in script & use 'On Error resume next in the function' data is written to excel sheet.But when i dont use exception handling it throws above errors.
Scenario3: When i use exception handing in the function and have teh function in func library, script runs but data is not written to excel sheet.
Reply
#3
Not Solved
Shwetha,
Remove the on error resume next and put the code on debug mode. Trace the flow and you will know the issue.
Basanth
Give a fish to a man and you feed him for a day..Teach a man how to fish and you feed him for life.
Reply
#4
Not Solved
Shwetha,

U need pass 3 more parameters in Geturlstatus function

Call Geturlstatus(url,mysheet,nam,a).

In the function change roc+1 to a+2. I tried by changing this and it is working fine

Try and let us know the result.
Reply
#5
Not Solved
Thanks for the info,Function is being called and data is written to Excel. But getting an exception for objhttp.send as "Access Denied".
Captured the error number(21479XXX), but was unable to analyse on the exception. Please let me know if this is something to do with configurations.
Note:This is happening on any web page on my machine.
Reply
#6
Not Solved
There is no access for u for the url
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
Question [HELP]Button no longer works in the transaction ME21N(SAP/QTP) rafaponzio 11 9,556 12-21-2022, 06:08 PM
Last Post: Carlos Veras
  Calling a Function in Function Library when function is defined in an Action jitenderkkr 0 2,769 11-27-2014, 12:53 PM
Last Post: jitenderkkr
  DP is not returning the whole table data content soumen 6 4,734 10-02-2013, 12:05 PM
Last Post: vvcyril
  Same code on running with UFT11.5 gets slow and browser hangs but works fine inQTP11 Rashi 1 2,412 03-02-2013, 04:12 PM
Last Post: vinod123
  Script running more times than the values in global data table TPavani 5 4,146 10-04-2012, 11:18 PM
Last Post: krr

Forum Jump:


Users browsing this thread: 2 Guest(s)