Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
User Defined Function - Return value
#1
Hi,
I feel so stupid because I can't figure this basic programming.
I am trying to utilize more user-defined functions in my macros.

I have been able to pass str variables to and from the user defined function and it worked fine.
But now there is a condition that depends on whether the user defined function worked properly and found what it was looking for.

I can't seem to get it to just return a value (0 or 1) and then have a decision tree based on that in the calling macro.

This is the syntax I have been trying to implement after looking through the help menu


The calling Macro is Macro1

Macro 1
Code:
Copy      Help
str accn;; accn will be used to define the window name in a later Acc statement in the function T2Series
GetPACSAccn accn;; GETPACSAccn gets the variable accn to be passed along in T2Series

int ifseriesfound
ifseriesfound = T2Series (accn)

if ifseriesfound = 1
,OnScreenDisplay    "found it"
if ifseriesfound = 0
,OnScreenDisplay "didn't find it"

The user-defined function is:

T2Series

Code:
Copy      Help
;/
function str&accn

Acc a=acc("(T2SeriesType1)|(T2SeriesType2)" "LISTITEM" win(accn "#32770") "SysListView32" "" 0x1002);err
if (!a.a) ret
a.Mouse(0)    
;

I am confused on how to get it to return the correct value or "validity" testing-
I know with some functions you can have a statement like:

Code:
Copy      Help
int i=findcr(f '.')

and then ret i

but I don't know how to set up a statement like this with the Acc statement type of function

I know this is basic programming but I think if I can get a handle on this, my macros will be much more robust.....

Thanks,
Stuart[/quote]
#2
ret 1

at the end.

-------------

Also add #:

function# ...

It is not necessary but then you will see in status bar that the function returns an int value.

------------

Shorter macro code:
Code:
Copy      Help
str accn;; accn will be used to define the window name in a later Acc statement in the function T2Series
GetPACSAccn accn;; GETPACSAccn gets the variable accn to be passed along in T2Series

if T2Series(accn)
,OnScreenDisplay   "found it"
else
,OnScreenDisplay "didn't find it"
#3
Thanks Gintaras,
I was able to shorten it even more, like this:

Code:
Copy      Help
if T2_Series(accn); out "success";else goto g2

If I want to run a series of these functions, can I enter them into a kind of foreach statement collection

each time something runs you run the next function in a series (collection?) of macros or functions?


str seriespositioner =
function_for_moving_to_position1
function_for_moving_to_position2

I hope this isn't too confusing.
Thanks
Stuart[/quote]
#4
I never needed that. Try call.

Maybe instead of using different functions you can use same function with different argument value:

int i
for i 0 n
,function_for_moving_to_position(i)
#5
"Call" is the key!

I will try something like this and let you know if it works..

str flair = "GetFLAIR"
str T2 = "GetT2"
str T1Pre = "GetT1Pre"


str seriescoll =
flair
T2
T1Pre

str seriesbucket

foreach seriesbucket seriescoll
call(seriesbucket accn)

Stuart
#6
Note that with call, if you want to pass a variable by reference (where the argument in the function is like str&s), you have to use &, like

call "functionname" &accn

but not like

call "functionname" accn


Forum Jump:


Users browsing this thread: 1 Guest(s)