Updating TextArea on the fly

I am trying to update a textarea in a module. However the textarea is only updated once the module is completed.

taMessages.AppendText("Processing… ")

Do I need to add a handler? If so can someone help with an example, thanks.

you can use a timer to refresh your user interface periodically

You may need to change your code to run in steps in a timer or in a thread.
This way the main thread has time to redraw the user interface.

taMessages.Invalidate … which will update at the next yield
taMessages.Refresh … do it NOW… (not normally reccomended)

Thanks for you input, I should mention it is a web textarea, I am trying to use it as a running log for the user.

On a WebTextArea, you should definitely do the updates in a timer. There is no UI update until an event is over, so even Refresh would not work.

You should refactor your module so if for instance you use a loop, it takes place in a multiple timer instead.

Move it from General to Web then.

Thanks everyone for your suggestions. Still have not achieved a running log displayed in a dialog.

Did you try using a timer as suggested? You will need to “unroll” your loop.

for index = 0 to 10
    doSomething(index)
    taMessages.AppendText("Processing: " + str(index))
next

Becomes

// in WebTimer.Action, Mode is ModeMultiple
// index is now a webpage property, initialized to 0
doSomething(index)
taMessages.AppendText("Processing: " + str(index))
index = index + 1
if index > 10 then me.Mode= Timer.ModeOff

Each time the timer fires, it does one iteration of the loop and updates the textarea. That allows the update to be sent to the browser between iterations.

Note that it is necessary to use a server-side timer, not the WebTimer that is in the library.

Drag a generic object to the webPage and make its Super Timer.

It works perfectly here, reading a text file to emulate the logs.

WebPage properties :

Public Property f as folderitem Public Property t as textinputstream

In a button action

f = SpecialFolder.Desktop.Child("princess.txt") If f <> Nil Then If f.Exists Then // Be aware that TextInputStream.Open coud raise an exception Timer1.Mode = Timer.ModeMultiple End If End If

In the Timer Action event

[code]Sub Action() Handles Action
if t = nil then
t = TextInputStream.Open(f)
t.Encoding = Encodings.MacRoman
end if

if not t.EOF then
Try
TextArea1.AppendText(t.Readline+EndOfLine)
Catch e As IOException
MsgBox(“Error accessing file.”)
End Try
else
t.close
me.mode = Timer.ModeOff
end if

End Sub
[/code]

Thanks Tim, I have tried as you have suggested to no avail and now will try Michael’s suggestion. Thanks

webtextareaonthefly.xojo_binary_project

Use any text file to replace princess.txt

Hi Michel, thanks for all your efforts and I do really appreciate the time taken from everyone to resolve my issue.

Michel suggestions works well when the timer exists on a page, which is great. However from this page I have a dialog popup with the text area and this where I execute and try to update the text area in the dialog.

When I tried to compile the timer expects class WebPage error.

So I need to rethink the design, thanks.

Leave all logic on the window, and simply address TextArea with the dialog name as prefix.

Leave all logic on the webPage, and simply address TextArea with the dialog name as prefix.