vbscript - Recursive Function return value in vb script -


please see below function fnwaitcheckfinalstatus if else part executed in below code value return function fnwaitcheckfinalstatus coming blank because function called recursively fnwaitcheckfinalstatus.

is there way return value of fnwaitcheckfinalstatus after exit function function should exit state.

how can make possible , pointers on this.

function fnwaitcheckfinalstatus(objstatusbar)      dim blnretvalue : blnretvalue = true     dim : i=0       if objstatusbar.exist         strvalue=objstatusbar.getroproperty("text")                       wait 10             strvalue=objstatusbar.getroproperty("text")         loop while strvalue = "task started"      end if      strvalue1=objstatusbar.getroproperty("text")     if strvalue1="task executed successfully"         blnretvalue1=true         fnwaitcheckfinalstatus = blnretvalue1         exit function     elseif strvalue1="task execution failed"         blnretvalue1=false         fnwaitcheckfinalstatus = blnretvalue1         exit function     else         call fnwaitcheckfinalstatus(objstatusbar)     end if    end function 

consider "pass-through"ing function result if return recursion, in code (note line !!! comment):

function fnwaitcheckfinalstatus(objstatusbar)      dim : i=0       if objstatusbar.exist         strvalue=objstatusbar.getroproperty("text")                       wait 10             strvalue=objstatusbar.getroproperty("text")         loop while strvalue = "task started"      end if      strvalue1=objstatusbar.getroproperty("text")     if strvalue1="task executed successfully"         fnwaitcheckfinalstatus = true     elseif strvalue1="task execution failed"         fnwaitcheckfinalstatus = false     else         fnwaitcheckfinalstatus=fnwaitcheckfinalstatus(objstatusbar) ' !!!     end if    end function 

also, eliminated result buffer variable. don´t need it, can scratch it.

also, i'd avoid exit function in case keep code simpler (one entry point, 1 exit point), eliminated that, too.

generally speaking, there no obvious reason using recursion here since pass same argument receive, recursive call same caller scope. use loop instead.


Comments

Popular posts from this blog

javascript - Jquery show_hide, what to add in order to make the page scroll to the bottom of the hidden field once button is clicked -

javascript - Highcharts multi-color line -

javascript - Enter key does not work in search box -