Looking for better solution

I have a smart device that I’m controlling with URL commands.

This statement is located in the “Change” action event in a ComboBox and I am changing the brightness value:

SDConnection.send(“Get”, “http://” + S_Address.value + “/Light/”+Channel.value+"?brightness="+ Me.value)

The problem is when I enter a new brightness value, XOJO triggers this event three times for some reason and crashes with an exception on the third round.

I’ve got around it with a flag that stops executing the repeat and is reset when the cursor once again enters the ComboBox:

If flag = False Then
SDConnection.send(“Get”, “http://” + S_Address.value + “/Light/”+Channel.value+"?brightness="+ Me.value)
Flag =True

This feels like a patch to me that could be avoided. Ideas?

Catch and handle the exception?


Are you entering a value with three digits, by any chance?

I’d use a Set button since you want to make sure the user has finished entering a value before attempting to trigger the call.


I use a timer that is started each time the change event fires. The timer waits a second or 2, in case the user is not finished typing. Put your code in the timer event.

1 Like

i remember urlconnection use 1 connection and you need to wait until its finished to use send again.
should work with .SendSync

or u use a tcp socket, connect and send a http header with get …
you can drag drop (from library) a tcp socket into a window and then add the events.

Good suggestion but after reading the notes about sendsync I decided to go with the flag but place the flag reset in the URLConnection.ContentRecieved:

Be aware that calling SendSync can cause your app’s UI to “freeze” while it waits for the result. For normal processing you may want to use the asynchronous Send method instead.

Feels a little cleaner now and seems to work fine. Thanks to all of you for the direction on the cause of the exception. It got me thinking about the multiple events.