udf return value not available to caller

Started by sense2k, April 13, 2015, 08:48:14 AM

Previous topic - Next topic

sense2k

Hello
I using 2011a.  modifying an existing script by adding an additional udf.  I need to use the return value (which basically is a count) as the limit in a For loop.  When I run it it says "uninitialized variable etc etc"
I have place a message(..) in the function and I know it's doing what it's supposed to do.
All my UDF's are defined before the main section.
Can someone tell me what I'm doing wrong?

Thanks

td

Likely cause is faulty logic in your script but since you haven't provided the logic, it is difficult to point out the fault.
"No one who sees a peregrine falcon fly can ever forget the beauty and thrill of that flight."
  - Dr. Tom Cade

td

Should have added that not properly closing a structure block with an 'endif', 'next', or 'endwhile' as the case my be can sometimes cause errors that seemingly defy explanation.
"No one who sees a peregrine falcon fly can ever forget the beauty and thrill of that flight."
  - Dr. Tom Cade

sense2k

Hello
Thx for replying.
Here is the script
I'm guessing it has to do with the way I break out of the while @true
but I don't know how to correct it
Thanks for looking at it and helping me

td

It is not entirely clear how much of your script is intentional as apposed to incidental but one thing is certain.  Never use a goto statement to break out of a structure of any kind.   The following script illustrates one of several possible alternatives but you would need to base your script on your actual intentions.

Code (winbatch) Select
#definefunction getddirct(ddiroot)
   ddirct=0

   ;dirchange(ddiroot)
   ;currdir=dirget()
   dirlist=diritemize(ddiroot:"*.*")

   nCount = ItemCount(dirlist, @Tab)
   for i = 1 to nCount
      dataxxxdir = ItemExtract(i, dirlist, @Tab)  ; or
      ;;dataxxxdir = ddiroot:ItemExtract(i, dirlist, @Tab) ?????
      firstfour = strindex(dataxxxdir,"data",1,@fwdscan)
      if firstfour <> 0
         ddirct=ddirct+1
      endif
   next

   return ddirct
#endfunction

;********************* M A I N ***********************

dirchange("C:\Projects")

currdir=dirget()
ddirct = getddirct(currdir)
message("ddirct is",ddirct)



"No one who sees a peregrine falcon fly can ever forget the beauty and thrill of that flight."
  - Dr. Tom Cade

sense2k

hi
yeah I thought it was a bad idea.  I got my value by changing the udf to a subroutine
but i'm still working on cleaning up the logic

thanks a lot

td

You can get the value from a user defined function by placing your function call on the right-hand side of an assignment statement with a variable on the left.  But a subroutine works too.   
"No one who sees a peregrine falcon fly can ever forget the beauty and thrill of that flight."
  - Dr. Tom Cade

sense2k