Progress window while loading file

Hi there!

I’m new to Xojo, with no programming experience. I got the basics easily, by working through the free Xojo programming workbook. (Thanks for providing this!).
In chapter 9, I learned to deal with files (open, save files). As an addition to the described “Hands on with files”, I tried to implement a progress window, that will be shown while opening files:

  • I created a separate Window with an Inderterminate Progress Bar (for simplicity reasons).
  • Within that window, I created a Method with one parameter, to set the window title while dealing with files (“Opening file…” or “Saving file…”).
  • In the OpenButton Action event I added ProgressWindow.Show and ProgressWindow.ShowProgress(“Loading…”) before opening the file stream

That’s the code in the OpenButton Action Event:

[code]dim myFile As FolderItem
dim d As New OpenDialog
dim textData As TextInputStream
Dim rtf As StyledText

d.Title = “Select a File”
myFile = d.ShowModal
if myFile <> nil Then
ProgressWindow.ShowModal
ProgressWindow.ShowProgress(“Loading file…”)
textData = TextInputStream.Open(myFile)
EditingField.StyledText.RTFData = textData.ReadAll
textData.Close
ProgressWindow.Close
TheFile = myFile
Self.Title = TheFile.Name
end if[/code]

The code in the Progress Windows’ ShowProgress Method simply sets the window title:

ProgressWindow.Title = status

The progress window will indeed be shown on runtime, but the file isn’t loading. It’s stuck at this position. I’m pretty sure it’s a beginner’s error or just a logical error. But it would be helpful if you explain me WHY this is not running correctly.

Try

ProgressWindow.Show

instead of

ProgressWindow.ShowModal

Explanation:
ShowModal displays the window and causes the current method to stop executing until the window closes or becomes invisible.
https://documentation.xojo.com/index.php/Window.ShowModal

Thanks for the quick reply! That works now. Only the Inderterminate ProgressBar is not moving, but I guess that’s because the other methods are executed… I assume that multiple executions at the same time will be covered in later chapters.