Hello Everyone

I was looking at the Alpha Message Board today and saw a closed thread where the user was looking for help creating an embedded progress bar on their application form. Several people replied but none actually answered the query and now the thread is closed so I thought I would do a quick session to show how it is done.

First watch this short video to see it in action.

 

So now you have seen it work, lets look closer at the code.

ListSource = remove_blank_lines(ListSource)
dim fndcnt as N
dim nFSize as N
fndcnt = 0
nFsize = 0
UpdateList = 4.1 / *count(listSource)
topparent:text2.Object.width = .1 
topparent:text2.show()
for each sel_file in ListSource
    fndcnt = fndcnt + 1
    nFsize = nFSize + file_get_size(Sel_File)
    FileMgtSystemS:text1.text = file.filename_parse(sel_file,"NE")+crlf()+ "Found:   "+str(fndcnt,6,0,",")+CRLF()+"File Size: "+bytes_to_mega(file_get_size(Sel_File),2)+crlf()+"Total Space Used: "+bytes_to_mega(nFSize,2) 
    topparent:text2.Object.width = topparent:text2.Object.width + UpdateList 
    ui_yield()
    FileMgtSystemS:text1.Refresh()
    xbasic_wait_for_idle()
next
FileMgtSystemS:text1.text = "Thank you for waiting; We Found: "+str(fndcnt,6,0,",")+" matches for your search string."+crlf()+"Total Space Used: "+bytes_to_mega(nFSize,2)+crlf() + "Use the Action Command Dropdown List to work with the found files." 
ui_freeze(.t.)
if vTLWatch =1 then
    vTLWatch = 0
else if vTLWatch = 0 then
    vTLWatch = 1
end if
topparent:text2.Object.width = .1 
topparent:text2.hide()

ui_freeze(.f.)

For this procedure to work correctly you need a few variables and a text object. Our variables are

  • fndcnt
  • nFSize
  • UpdateList

and our text object is

  • text2

Our Text object property is set to Hidden when the form loads. When the user clicks Search, the onPush event runs the search and builds ListSource

Next we remove any blank lines in ListSource, set our variables to 0 and our text object is set to show and given a starting width

text2.show()

text2.Object.width = .1

Now the magic begins The full width of our text2 object on the form is 4.1 inches. We divide that by the count of the lines in our List.

UpdateList = 4.1 / *count(listSource)

This gives us an increment value for the growth of our progress bar. Using the function For each .. Next we step through our ListSource  and increment up our variables modify our text message box with the current line result and increase the size of our progress bar(text2.Object.width) by the value of the variable UpdateList. I use ui_yield and xbasic_wait_for_idle() before going to Next. This insures the bar and text update on the screen. Finally we do our cleanup and rehide our text2 object until it is needed again.

That’s it short and sweet and this process will work on Alpha Software v8 and up to Alpha Anywhere. I hope all of you find this useful and as promised the next blog lesson will continue with our Sudoku Puzzle Application. Hope to see you then.