Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.
|
Forum Index : Microcontroller and PC projects : Numberbox Bug
Author | Message | ||||
panky Guru Joined: 02/10/2012 Location: AustraliaPosts: 1099 |
I think there is a bug in NumberBox (and TextBox). The code below demonstrates the problem. This issue was discovered by KeepIS in a previous post. ' NumberBox Bug Demo ' MMBasic 5.04.05 ' PM MZ144 Backpack with 7" LCD cls const LED1 = 1 const SWITCH1 = 2 const NUMBOX1 = 3 dim ontime GUI led LED1,"Heartbeat",50,200,10,RGB(red) print "Test showing reading and writing of GUI LED CTRLVAL" print "Press any key to go to next test" do input "Enter on time of LED in seconds ",ontime ' here we write and read the CtrlVal for GUI LED CtrlVal(LED1) = ontime * 1000 ' convert to mS if ctrlval(LED1) => 1 then print "LED is ON" endif pause (ontime * 1000) * 2 if ctrlval(LED1) = 0 then print "LED is OFF" endif if inkey$ <> "" then ' any key to exit exit DO endif loop print "Test to show GUI SWITCH turning GUI LED On/Off" print "This test shows TOUCH does not cause issues with GUI LED" print "Press any key to continue to next test" gui switch SWITCH1,"On/Off",400,200,80,80,rgb(yellow),rgb(green) ' here we read switch CtrlVal and write to LED CtrlVal ' with no ill effects Do If CtrlVal(SWITCH1)=0 Then 'test the staus of the switch CtrlVal(LED1) = 0 ' if switch OFF, set led OFF Elseif ctrlval(SWITCH1) = 1 then ' else if switch ON, CtrlVal(LED1) = 1 ' set led ON EndIf if inkey$ <> "" Then ' any key to exit exit DO endif pause 100 Loop print "GUI LED switching ON/OFF with SWITCH" print "- touching the SWITCH has no negative impact on the program" print " other than switching the LED On/Off" print "Touching the NUMBERBOX will crash the program" print " Try it and see!!! " GUI NUMBERbox NUMBOX1,1,1,100,100,RGB(white),RGB(blue) Do If CtrlVal(SWITCH1)=0 Then 'test the staus of the switch CtrlVal(LED1) = 0 ' if switch OFF, set led OFF Elseif ctrlval(SWITCH1) = 1 then ' else if switch ON, CtrlVal(LED1) = 1 ' set led ON EndIf if inkey$ <> "" Then ' any key to exit exit DO endif pause 100 Loop ' it would appear that touching a NUMBERBOX or a TEXTBOX changes the ' variable type of CtrlVal from float to string for all further uses ' of CtrlVal rather than just for these two. Doug. ... almost all of the Maximites, the MicromMites, the MM Extremes, the ArmMites, the PicoMite and loving it! |
||||
panky Guru Joined: 02/10/2012 Location: AustraliaPosts: 1099 |
Further to my last post above, the error only occurs while the NumberBox or TextBox keypads are active on the screen. If you programatically try to read the value of a GUI Switch or GUI LED while the keypad is active on the screen, CtrlVal(#n) will return the Control name eg. Switch 1 etc. rather than the Control value. Once Ent has been pressed and the keypad disappears, everything is back to normal. So perhaps not a bug, just "Do not read the value of a control such as LED or SWICT while the keypad for NumberBox or TextBox is active on the screen" Regards, Doug. ... almost all of the Maximites, the MicromMites, the MM Extremes, the ArmMites, the PicoMite and loving it! |
||||
Grogster Admin Group Joined: 31/12/2012 Location: New ZealandPosts: 9080 |
|
||||
panky Guru Joined: 02/10/2012 Location: AustraliaPosts: 1099 |
@G The issue is more that if you are monitoring the status of the gui switch or the gui led, the value returned by CtrlVal(#n) is a float however from the time between pressing a NumberBox and a value and then the Ent key on the keypad, CtrlVal(#n) is a string. So within a program, you must ensure that the program does not attempt to read the value of a gui switch or gui led when there is a chance of someone pressing the NumberBox - if the program does, it will crash. It's an unlikely situation but one example would be where you wanted to flip a gui led to indicate a heartbeat - this would run in some form of background loop but at the same time, you want do something with NumberBox or TextBox. CONFLICT!!! Doug. ... almost all of the Maximites, the MicromMites, the MM Extremes, the ArmMites, the PicoMite and loving it! |
||||
Geoffg Guru Joined: 06/06/2011 Location: AustraliaPosts: 3167 |
Thanks for the detective work in this. It does not sound right and I will fix it for the next release. Geoff Geoff Graham - http://geoffg.net |
||||
Grogster Admin Group Joined: 31/12/2012 Location: New ZealandPosts: 9080 |
@ panky - Oh. I see. I interpreted that incorrectly then - apologies. An interesting one you have found there! (thumbs-up, because any obscure bug like this, can be very hard to find in the first place, but because you have, I am sure Geoff will squish it in no time.) Smoke makes things work. When the smoke gets out, it stops! |
||||
Print this page |