Home
JAQForum Ver 20.06
Log In or Join  
Active Topics
Local Time 18:44 17 May 2024 Privacy Policy
Jump to

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: Australia
Posts: 1099
Posted: 01:57pm 16 Aug 2017
Copy link to clipboard 
Print this post

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: Australia
Posts: 1099
Posted: 06:38pm 16 Aug 2017
Copy link to clipboard 
Print this post

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 Zealand
Posts: 9081
Posted: 07:58pm 16 Aug 2017
Copy link to clipboard 
Print this post

  panky said  "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"[/Quote]

I would agree with that. Normally, you only affect the changes, once you have entered the number you want. Reading the value of the keypad control BEFORE you press ENT I would expect MMBASIC to return a 1 or a zero, as you have not specified the number yet - you do that once you touch ENT.

I will wait and see what Geoff and Peter say about that, but I would fully expect that the CtrlVal for NumberBoxWhatever would NOT be set until you actually touch ENT and the GUI control closes.

MHOO.
Smoke makes things work. When the smoke gets out, it stops!
 
panky

Guru

Joined: 02/10/2012
Location: Australia
Posts: 1099
Posted: 09:39pm 16 Aug 2017
Copy link to clipboard 
Print this post

@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: Australia
Posts: 3167
Posted: 12:25pm 17 Aug 2017
Copy link to clipboard 
Print this post

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 Zealand
Posts: 9081
Posted: 01:58pm 17 Aug 2017
Copy link to clipboard 
Print this post

@ 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


To reply to this topic, you need to log in.

© JAQ Software 2024