'**** HEADER ************************************************************
'EXNET-N4.PF3 (release .02)
'Copyright (c) 1990-1991 Applied Resource Technologies, Inc.
'P.O. Box 64381, Dallas, Texas 75206 U.S.A. (214) 855-0449
'Description: One use for nxmitmsg(). Demonstrates picking a desired
'             connection number out of the PTSP variable ulist[] in
'             order to send a message to a specific user, in this case
'             uname or "self"
'**** FUNCTION DECLARATIONS *********************************************
'library
external nuserlist() nxmitmsg()
external progress() progtag()
'core
global setup() control() finduser() main_exit()
'**** VARIABLE DECLARATIONS *********************************************
'library
public ulist[1,5] ucount uname uconn       ' EXTERNAL, if using setenv()
public ptstr psa
'core
global exlpath
global conn#
'**** CODE **************************************************************

MAIN
if setup() = 0
     control()
end if
main_exit()
END MAIN

function control()
local i k
if finduser() = 0
     while k <> {Esc}
          screen clear box 1 1 scrheight scrwidth 0 0 no-border
          screen print 5 20 fgpleasing bgpleasing \
                 "When the count reaches 14, you will get a message"
          screen print 7 20 fgpleasing bgpleasing \
                 "Count:"
          for i = 1 to 20
               milli-wait 500
               screen print 7 27 fgpleasing bgpleasing \
                      (format(str(i),"R2"))
               if i = 14
                    if nxmitmsg("The count is now 14",str(conn#)) = 0
                         progress(fgpleasing,bgpleasing, \
                                 "Message result was:" & group(ptstr,1),1)
                         progtag(fgpleasing,bgpleasing,"Press any key")
                         inchar
                         screen shortrestore psa
                    end if
               end if
          end for
     end while
else
     beep
     screen shortrestore psa
     progress(fgerror,bgerror,"ERROR: Could not get user names... aborting",1)
     progtag(bgerror,bgerror,"Press any key")
     inchar
end if
end function 'control()

function finduser()
local err_stat i
err_stat = -1
if nuserlist() = 0                   ' always work with a "fresh" user list
     for i = 1 to ucount             ' look at each user's data
          if ulist[i,4] == uname     ' compare to "self" for this example
               conn# = ulist[i,3]    ' connection number value for "self"
               if conn# > 0          ' user is on-line
                    err_stat = 0
               end if
          exit for
     end if
     end for
end if
return (err_stat)
end function 'finduser()

function setup()
local err_stat
err_stat = 0
exlpath = "\smartii\poptools\lib\"
error off
clearerror
load exlpath|"displib.psl"
if cerror = 0
     screen clear box 1 1 scrheight scrwidth 0 0 no-border
     progress(fgpleasing,bgpleasing,"EXNET-N4.PF3... setting up",0)
     load exlpath|"netlib-n.psl"
     if cerror <> 0
          err_stat = -1
     end if
else
     err_stat = -1
end if
error on
return (err_stat)
end function 'setup()

function main_exit()
unload "displib.psl"
unload "netlib-n.psl"
end function 'main_exit()

