For Next | While Wend Observation

For i As Integer = 1 To 5
  MessageBox(Str(i))
Next

I’ve just installed 2021 release 1.1 on Mac and Windows.

I’m having issues with looping constructs like For-Next and While-Wend.

Using 2019 R3.2 (Web 1.0), the code above presents consecutive message boxes with 1 then 2 then 3 then 4 then 5. This behaviour is expected.

However, since 2020 R1 through 2021 R1.1 (Web 2.0), the code above presents consecutive message boxes with 4 then 3 then 2 then 1 then 5. This behaviour is unexpected.

The exact same issue when I refactor the code into a While-Wend looping structure.

Same issue on Mac and Windows.

Could someone please confirm.

Kind regards, Andrew

It looks like what is happening is that Xojo is sending all the MessageBox, that’s why is darker than normal around the MessageBox with a 4:


Edit: you can have the same behavior in Web 2.0 as in Web 1.0 by using JavaScript Alerts:

For i As Integer = 1 To 5
  Me.ExecuteJavaScript("alert('" + Str(i) + "');")
Next

Hello @AlbertoD ,

My example was not something I would do in an actual app but I found it curious.

Thank you for the workaround, although still a bug in the sense the MessageBox(es) are all sent to the browser at once and displayed out of order.

Kind regards, Andrew

They are shown in order, they just appear to be out of order in a synchronous mindset. The last is shown topmost because it is the last and its calculated z-index will be higher than the previous one. The first one sent will be at the bottom of the stack because it was first.

Also remember that Web is asynchronous. If you stop the execution of the JavaScript in the client browser, you’re creating more problems than you solve, so when you show a bunch of MessageBoxes in quick succession, they all get sent at the same time, in the same packet, and a round-trip check by the framework would slow things down also.

A good feature request might be to cache the MessageBox JavaScript calls on the client-side and show the next when the current one is closed.

2 Likes

Why 5 is the first one sent and 4 the last in a for i = 1 to 5?

I expected, at least, 5 be the last one so it will show above all others.

1 Like