Contributed by: Rene' DALLE
One of the questions in the "New objects for VisPRO" was the request for a progress bar. I have used the slider object in such a capacity, combining it withe the timer event:
First I use the following subroutine to initialize the slider:
/**************************************************/
/* */
/* Set Up Progress Slider Presentation */
/* */
/**************************************************/
arg max, inc
/*
arg: Max > number of tick spaces on the slider,
inc > Spacing for value, in number of ticks.
Example: call Set_Slider 20, 5
20 spaces of 5% with writing every 5 ticks or
0, 25%, 50%, 75% and 100%
*/
/* Set slider range PROGRESS Slider */
Max_range=VpGetItemValue(window, 'PROGRESS', 'GETRANGE')
/* Set all tick sizes PROGRESS Slider */
CALL VpSetItemValue window, 'PROGRESS', 'SETTICK', 4
num = (100 * inc)/ max
value = 0
do index = 0 to max by inc
if (value > 0) then
mark = value || '%'
else
mark = '0'
CALL VpSetItemValue window, 'PROGRESS', 'SETTICK', index, 8, mark
value = value + num
end
/* Set shaft size PROGRESS Slider */
CALL VpSetItemValue window, 'PROGRESS', 'SETSHAFTSIZE',10
current_value = 0 /* current slider check */
max_value = 1 /* maximum slider check */
duration = 1000 /* slider refresh timer */
[End Subroutine]
This is placed in the "Procedure Files" folder.
Now, as part of the "Opened" event for the controling form, I place the following code:
/* Get slider range PROGRESS Slider */
Max_range=VpGetItemValue(window, 'PROGRESS', 'GETRANGE')
call set_slider 20, 5
current_value = 0 /* current slider check */
max_value = 1 /* maximum slider check */
importing = 0 /* elapse time slider check */
duration = 500 /* slider refresh timer */
Where "PROGRESS" is the name of the slider, and in the "Expired Timer" event:
/* H:\OS2\PROJECTS\cc!Mail Rejects\Main When Timer Expired */
Arg window
CALL VpWindow window,'STOPTIMER'
value = (Max_range * Current_value) / Max_value
/* Set item value PROGRESS Slider */
CALL VpSetItemValue window,'PROGRESS',value
/* duration in 1/1000 secs */
CALL VpWindow window,'STARTTIMER',duration
[end]
When I want to use the slider, I make it appears as in this code:
/* Set item value PROGRESS Slider */
CALL VpSetItemValue window,'PROGRESS',0
/* Show item PROGRESS Slider */
CALL VpItem window,'PROGRESS','SHOW'
/* Add item to end MESSAGES Multi-Line Entry Field */
CALL VpAddItem window, 'MESSAGES', 'END', "*** Loading Alias File " || Alias_file || " ***" || CR_LF
num = 1
Alias.num = '.Mitel.COM'
current_value = 0 /* current slider check */
max_value = stream(Alias_File,C,"QUERY SIZE") /* maximum slider check */
/* Select item LOAD_ALIAS Push Button */
CALL VpSelect window,'LOAD_ALIAS'
/* duration in 1/1000 secs */
CALL VpWindow window,'STARTTIMER',duration
[end]
to show the progress when loading a file.... Here is the "LOAD_ALIAS" event button,
called recursively until the end....
/* Event LOAD_ALIAS, Clicked/selected */
Arg window self
if (lines(Alias_file) > 0) then do
num = num + 1
line = linein(Alias_file)
current_value = current_value + length(line) + 2
parse upper var line Alias.num Address
/* Select item LOAD_ALIAS Push Button */
CALL VpSelect window,'LOAD_ALIAS'
end; else do
CALL VpWindow window,'STOPTIMER'
CALL stream Alias_file, C, 'CLOSE'
/* Set item value PROGRESS Slider */
CALL VpSetItemValue window,'PROGRESS',Max_value
Alias.0 = num
/* Hide item PROGRESS Slider */
CALL VpItem window,'PROGRESS','HIDE'
/* Add item to end MESSAGES Multi-Line Entry Field */
CALL VpAddItem window, 'MESSAGES', 'END', "*** There were " || num || " Aliases loaded!" || CR_LF
/* Select item INIT_FILES Push Button */
CALL VpSelect window,'INIT_FILES'
end /* end do */