Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Returning Queue values from function

Status
Not open for further replies.

newtoclarion

Programmer
Jul 20, 2011
66
SA
Hello everybody
I have this function/procedure which saves results in a Queue.
What I want is to return these values normally to be used in the calling routine.

Now I am defining the Queue in the function as Global, so I can read it and copy its contents to a queue in the calling procedure.

But I am looking for a better way to make my function independent without using the global variables.

Any suggestions are extremely appreciated

 
Hi,

you can you use a reference parameter --> myFunction(*QUEUE)
So you dont need global variable.

cagiv
 
Thank you Cagiv but may be my idea was not clear
I will give a simple example:

Code:
! calling function from screen button
      MyVar = get_list(1,4)
! Function will loop from 1 to 4 and saves results in Queue as an example
Code:
Function get_list(a,b)
 Loop i# = a to b
     ! Add to Queue
 end
 Return ! the Queue
! I want the values stored in the Queue to be stored in MyVar that can be used in the main routine.

Thank you



 
Thats's what i mean:

DATA Declaration in Main
l:MyQueue QUEUE
test STRING(20)
END

Call in Main:
FREE(l:MyQueue)
get_list(1,4,l:MyQueue)

Prototype Procedure get_List:
get_list(ULONG,ULONG,*pMyQueue)

PROCEDURE get_list(a,b,pMyQueue)
DATA
r:MyQueue QUEUE
test STRING
END
CODE
!Fill local Queue with Data
Loop i# = a to b
r:MyQueue:test = 'Test '& i#
end
!Transfer Data to referenced Queue
LOOP i# = 1 TO RECORDS(r:MyQueue)
GET(r:MyQueue,i#)
pMyQueue = r:MyQueue
ADD(pMyQueue)
END
 
Sry, i wrote:

Prototype Procedure get_List:
get_list(ULONG,ULONG,*pMyQueue)

i did mean:
Prototype Procedure get_List:
get_list(ULONG,ULONG,*Queue)

 
Dear newtoclarion,
As we are working in the same place.. make sure to write comments from your account :)

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top