Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
Home » Community » Newbie corner » Problem using a switch control
Problem using a switch control [message #45589] Fri, 11 December 2015 09:04 Go to next message
Giorgio is currently offline  Giorgio
Messages: 218
Registered: August 2015
Experienced Member
Hi there,
I have a problem with a switch control. In an application, I have a window that helps user to select some data. User puts a code into a filed, hit a button, and the application shows - using a switch control - some lengths (just to give context: the code is a cable and the lengths are the ones available for that cable). After that the user can choose one of the lengths. The problem is that when user passes over the options of the switch control, they get highlighted as they were selected. I know this description may sound obscure, so I attach a video. In the video I click and select an option, then I pass over other options and finally I click randomly on some options.
Thanks for any help,
Gio

[Updated on: Sun, 13 December 2015 19:58]

Report message to a moderator

Re: Problem using a switch control [message #45590 is a reply to message #45589] Fri, 11 December 2015 13:03 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
Testcase would be helpful, however, from what I see I bet that the problem is that all switch cases have the same value.

I think this would produce similar behaviour:

Switch sw;
...
sw.Add(0, "Case1");
sw.Add(0, "Case2");

[Updated on: Fri, 11 December 2015 13:03]

Report message to a moderator

Re: Problem using a switch control [message #45599 is a reply to message #45590] Mon, 14 December 2015 15:08 Go to previous messageGo to next message
Giorgio is currently offline  Giorgio
Messages: 218
Registered: August 2015
Experienced Member
Hello Mirek,
thank you for your post. I have used the debugger and it seems switch cases have different values. In fact, the value is assigned during a loop with a variable that is incremented. Anyway, I created a very small test case, attached. Please note that the test case is very small, most of the space is the sqlite db. As my application uses a MySQL db, I have created a sqlite db: please note that I got rid of a lot of tables, so maybe the db and application look incoherent. To reproduce the problem, launch the application and click on the "Select job order" button. A dialog opens: put in the active field the following order id 15036120901 (maybe it works with other order ids, but I tested that one) and hit return. After that, click on a switch case and then pass the mouse over other cases (try different cases, sometimes it works with a particular case). The problem is in lines 51-85 (specifically, lines 62-77), but I cannot locate it.
Thank you for the support,
Gio
  • Attachment: SWPR.zip
    (Size: 74.01KB, Downloaded 221 times)
Re: Problem using a switch control [message #45603 is a reply to message #45599] Mon, 14 December 2015 20:49 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
Giorgio wrote on Mon, 14 December 2015 15:08
Hello Mirek,
thank you for your post. I have used the debugger and it seems switch cases have different values. In fact, the value is assigned during a loop with a variable that is incremented. Anyway, I created a very small test case, attached. Please note that the test case is very small, most of the space is the sqlite db. As my application uses a MySQL db, I have created a sqlite db: please note that I got rid of a lot of tables, so maybe the db and application look incoherent. To reproduce the problem, launch the application and click on the "Select job order" button. A dialog opens: put in the active field the following order id 15036120901 (maybe it works with other order ids, but I tested that one) and hit return. After that, click on a switch case and then pass the mouse over other cases (try different cases, sometimes it works with a particular case). The problem is in lines 51-85 (specifically, lines 62-77), but I cannot locate it.
Thank you for the support,
Gio


			for(int j = 0; j < n_of_drums; j++)
			{
				DDUMP(query[DRUM]);
				dlgSelectDrums.lengthList.Set(i, AsString(query[DRUM]), ( AsString(query[METER]) + "m - N: " + AsString(k+1) + " of " + AsString(n_of_drums)));


query[DRUM] = 125
query[DRUM] = 125
query[DRUM] = 125
query[DRUM] = 140
query[DRUM] = 160
query[DRUM] = 160


...exactly what I have suspected...
Re: Problem using a switch control [message #45605 is a reply to message #45603] Tue, 15 December 2015 10:31 Go to previous messageGo to next message
Giorgio is currently offline  Giorgio
Messages: 218
Registered: August 2015
Experienced Member
Hello Mirek,
there is something I am missing. I knew that query[DRUM] can give multiple results with the same value, that is expected (to give context: user has to cut a long cable in "chunks", and usually some of those chunks have the same length; the switch control is used to select what chunk the user is currently cutting). What it is not really clear to me, is the "unique" index to be used in each switch element. I supposed that the first element of the .Set method was the one that had to be unique. In fact, in my code the first element is a counter (i) that is incremented each time in the loop: that was what I meant when I wrote that the switch cases have different values. Is there a way to fix my code or I have to think to a different approach?
Thanks,
Gio
Re: Problem using a switch control [message #45608 is a reply to message #45605] Tue, 15 December 2015 12:46 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
I see.

Well, the 'key' is the second argument to Set and right now should be unique (that said, while this is the first case when this causes the problem, maybe it is not necessary requirement and it would be possible to support your use-case directly).

Anyway, right now, fix is easy - use i as second argument too... (you will have to store sql[DRUM] in some array, but that is easy).

Mirek
Re: Problem using a switch control [message #45610 is a reply to message #45589] Tue, 15 December 2015 22:19 Go to previous messageGo to next message
mr_ped is currently offline  mr_ped
Messages: 825
Registered: November 2005
Location: Czech Republic - Praha
Experienced Contributor
			for(int j = 0; j < n_of_drums; j++)
			{
				DDUMP(query[DRUM]);
				dlgSelectDrums.lengthList.Set(i, AsString(query[DRUM]), ( AsString(query[METER]) + "m - N: " + AsString(k+1) + " of " + AsString(n_of_drums)));


pardon my ignorance (and laziness to check the zip with full source), but is it ok the for has "j" and the Set takes "i" in first parameter?

Also when the key is "AsString(query[DRUM])", you may produce string like "i,query[DRUM]" for keys, and then extract the query[DRUM] by splitting the key with ',', if you insist to have that data encoded in key. Just an option, I would probably consider in PHP (where the thing is slow as hell already anyway, and writing str manipulation is easy too)... but in U++ I think having a vector with query[DRUM] values around and using pure "i" (or j?) is easier to write, read and maintain...
Re: Problem using a switch control [message #45612 is a reply to message #45610] Wed, 16 December 2015 15:03 Go to previous messageGo to next message
Giorgio is currently offline  Giorgio
Messages: 218
Registered: August 2015
Experienced Member
Well there are two nested loop, your laziness failed you Wink ... probably your solution is ok too, but I went for the Mirek's one (put data in a vector) and it works fine.
Re: Problem using a switch control [message #45613 is a reply to message #45608] Wed, 16 December 2015 15:10 Go to previous messageGo to next message
Giorgio is currently offline  Giorgio
Messages: 218
Registered: August 2015
Experienced Member
Hello Mirek,
I stored the data in an array, as per your suggestion, and it worked like a charm. Just a couple of lines of code and everything works. As far as regard supporting my use-case directly, I think it depends on developers. On one hand, as far as I know a workaround to deal with the case, to me is fine. On the other hand, maybe my use case could be useful to other people too.
Thank you again for your support,
Gio
Re: Problem using a switch control [message #45615 is a reply to message #45610] Thu, 17 December 2015 10:11 Go to previous message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
mr_ped wrote on Tue, 15 December 2015 22:19
			for(int j = 0; j < n_of_drums; j++)
			{
				DDUMP(query[DRUM]);
				dlgSelectDrums.lengthList.Set(i, AsString(query[DRUM]), ( AsString(query[METER]) + "m - N: " + AsString(k+1) + " of " + AsString(n_of_drums)));


pardon my ignorance (and laziness to check the zip with full source), but is it ok the for has "j" and the Set takes "i" in first parameter?

Also when the key is "AsString(query[DRUM])", you may produce string like "i,query[DRUM]" for keys, and then extract the query[DRUM] by splitting the key with ',', if you insist to have that data encoded in key. Just an option, I would probably consider in PHP (where the thing is slow as hell already anyway, and writing str manipulation is easy too)... but in U++ I think having a vector with query[DRUM] values around and using pure "i" (or j?) is easier to write, read and maintain...


Well you could also use MakeTuple....
Previous Topic: Multiple lines on EditString
Next Topic: Installation Problem in OpenSUSE Tumbleweed
Goto Forum:
  


Current Time: Tue Apr 16 08:17:36 CEST 2024

Total time taken to generate the page: 0.01400 seconds