Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Function handles diff arguments
#1
I'm making a replacement function for wait that asks to retry. It works fine except I would like to use different arguments (such as pass a window name or a handle) depending on the situation. How do I define the function so that it will accept either argument based on how it is called?

For example, here is my code... it fails if i pass it a string (ie: WaitFor2 "Window Name") it fails with "Error in test_waitfor2: expected numeric expression.";
Code:
Copy      Help
/
function [^waitmax] [hwnd] [str's] ;;waitmax: 0 is infinite.

Function WaitFor is template to create functions that wait for some condition.

waitmax is max number of seconds to wait. 0 is infinite.

int w=0
int n
str s2    

if(waitmax<0 or waitmax>2000000) end ES_BADARG
opt waitmsg -1

int wt(waitmax*1000) t1(GetTickCount)
rep
    rep
        0.1
        
         here insert code that checks for some condition
         and returns (ret or break) if it is true
        ;try to activate the window. if successful, exit function
        if hwnd>0
            w=act(hwnd)
        else
            w=act(win(s))
            err
        if (w>0)
            break
            
        if(wt>0 and GetTickCount-t1>=wt)
            break
            
    if (w>0)
        break
    
    ;if timeout, then bring up dialog to continue waiting or quit (indicate what we are waiting for)
    if s=""
        s2.from("Timed out waiting for: " s)
    else
        s2="Timed out"
    n=mes(s2 "" "ARI2!")
    if (n='A')                 ;;abort
        end "WaitFor2 timeout"
    if (n='R')                ;;retry (wait only 5 seconds)
        wt=5000
        t1=GetTickCount    
    if (n='I')                 ;;ignore
        break                
ret

By the way, this would be a nice default feature for the wait function to have!

Thank you


Messages In This Thread

Forum Jump:


Users browsing this thread: 1 Guest(s)