Is there a way to make a a procedure wait (not a module). I am writting code involving a Wiser comnunicating with another device through a TCP socket. I need the program to wait for the socket to open. The code works well when it is residing within a module. However, to avoid repeating the same code many times, I would like the code to be in a procedure but I can't find a way to implement the waiting procedure. 1. The "wait" and "waituntil" instructions are not available in procedures. 2. Using an "until" loop generates an error because the number of instructions per scan cycle is exceeded. A work around found is to add a "slow" instruction to the waiting loop like making an http request to an external website, but this is really not clean. Here is the code. Note IPSwitch is a pascal record structure, the names of the fields are self-explanatory. Procedure SwitchIP(TheSwitch : IPSwitch; OnOrOff : Boolean); Var cTime : Integer; begin With theSwitch do Begin { Open socket and wait until it is open } OpenClientSocket(SwitchSocket,Address, Port); cTime := RunTime + 3 ; [COLOR="Red"] repeat until ClientSocketConnected(SwitchSocket) or (Runtime > cTime) ;[/COLOR] { Send the on or off message string to socket } if OnOrOff then begin WriteClientSocket(SwitchSocket, OnString); end else begin WriteClientSocket(SwitchSocket, OffString); end; CloseClientSocket(SwitchSocket); end ; end;