/*
** $VER: Progress_Ex.thor 1.0 (6.9.95)
**   - Example script for the progressbar functions in THOR 2.0
**
*/

	options results

	if(substr(address(),1,4) ~= "THOR") then do
		parse arg thorport
		if~(show(p, thorport)) then do
			if ~(show(p, "THOR.01")) then do
				say "No THOR port found!"
				exit
			end
			else thorport = "THOR.01"
		end
	end
	else thorport = address()

	if ~show('p', 'BBSREAD') then do
		address command
			"run >nil: `GetEnv THOR/THORPath`bin/LoadBBSRead"
			"WaitForPort BBSREAD"
	end

	signal on ERROR

	address(BBSREAD)

	GETBBSLIST stem BBSLIST
	if(rc ~= 0) then 
	do
		address(thorport)
		REQUESTNOTIFY TEXT '"'BBSREAD.LASTERROR'"' BT '"_Ok"'
		exit
	end

	address(thorport)

	THORTOFRONT

	OPENPROGRESS TITLE '"Progress Test"' AT '"_Abort"' PCW 30
	if(rc = 0) then
	do
		window = result		/* Important !!! */

		do i=1 to BBSLIST.COUNT
			/* Display bbsname and reset progressbar.*/
			UPDATEPROGRESS REQ window TOTAL 50 PT '"'BBSLIST.i'"'
			do n=1 to 50
				/* Update progressbar 50 times for each bbs */
				UPDATEPROGRESS REQ window CURRENT n	
				if(rc ~= 0) then do
					/* Check if user aborted */
					CLOSEPROGRESS REQ window
					window = 0
					leave
				end
			end
		end
	end

ERROR:

	if(window ~= 0) then CLOSEPROGRESS REQ window

exit
