Home
JAQForum Ver 20.06
Log In or Join  
Active Topics
Local Time 04:20 30 Apr 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 : Textbox bug with example code...

Author Message
Grogster

Admin Group

Joined: 31/12/2012
Location: New Zealand
Posts: 9063
Posted: 02:33am 18 Jan 2016
Copy link to clipboard 
Print this post

Hi all.

I have been playing about with textboxes tonight, and cannot get past this problem.

When you try to delete any GUI control, or all off them, or only the ones you are using, AFTER you have created a textbox, going to a new screen generates a rouge numberbox that you do not ask for.

Please try this code, which demonstrates the problem:


START:
CLS
wait=10000

DATABASE:
SetTick 0,0,1
CLEARSCR
Text 65,25,"DATABASE MENU:",,7,3,RGB(red),RGB(white)
Text 75,100,"Access is restricted.",,4,2,RGB(yellow)
GUI textbox #1,250,175,250,50,RGB(white),RGB(black)
CtrlVal(#1)="##PASSWORD"
GUI caption #2,"Touch the password box or EXIT.",125,275,,RGB(cyan)
Font 7,2
GUI button #3,"EXIT",275,375,200,75,RGB(blue),RGB(gray)
Timer=0
Do
If CtrlVal(#1)="SYS" Then goto Confirm
If CtrlVal(#3)=1 Then GoTo START
Loop Until Timer>wait
GoTo START

END

'--------------------
'Obtain confirmation:
'--------------------
Confirm:
CLEARSCR
Text 65,50,"DATABASE MENU:",,7,3,RGB(red)
Text 65,125,"Database editor mode.",,4,2,RGB(yellow)
Text 95,200,"The system will ignore calls while in",,4,1,RGB(cyan)
Text 95,225,"editor mode. Calls received during",,4,1,RGB(cyan)
Text 95,250,"this time will be saved in the queue",,4,1,RGB(cyan)
Text 95,275,"and processed when you are finished.",,4,1,RGB(cyan)
Text 85,325,"Touch OK to proceed, or EXIT to cancel.",,4,1,RGB(white)
Font 7,2
GUI button #1,"EXIT",75,400,200,50,RGB(blue),RGB(gray)
GUI button #2,"OK",525,400,200,50,RGB(red),RGB(gray)
Timer=0
Do
If CtrlVal(#1)=1 Then GoTo START
If CtrlVal(#2)=1 Then GoTo EDITOR
Loop Until Timer>wait
GoTo START
'---------------------
'Main database editor:
'---------------------
EDITOR:
End

SUB CLEARSCR
Timer=0
Do:Loop Until Touch(UP)=1 'Wait until no touch control being touched.
X=Timer
If DEBUG then Print "Delete GUI in " + STR$(X) + " ms."
GUI delete all
CLS
End SUB

END



'================
'C-CODE ROUTINES:
'================

' BigFont.bas
' Font type : Full (95 characters)
' Font size : 16x16 pixels
' Memory usage : 3044 bytes
' Font downloaded from: http://www.rinkydinkelectronics.com/r_fonts.php
DefineFont #7 'BigFont
5F201010 00000000 00000000 00000000 00000000 00000000 00000000 00000000
00000000 00000000 800F0007 800F800F 800F800F 00070007 00000000 00070007
00000007 380E0000 380E380E 3006380E 00000000 00000000 00000000 00000000
00000000 300C0000 300C300C FE7FFE7F 300C300C 300C300C FE7FFE7F 300C300C
0000300C 40020000 F80F4002 401AF81F F01F401A 5802F80F F81F5802 4002F01F
00004002 00000000 100E0000 700E300E C001E000 00078003 700C700E 00007008
00000000 00000000 8019000F 80198019 080F000F F819980F E018F018 980FF019
00000000 00000000 00070007 000E0007 00000000 00000000 00000000 00000000
00000000 00000000 C001F000 00078003 000E000E 000E000E 80030007 F000C001
00000000 00000000 8003000F E000C001 70007000 70007000 C001E000 000F8003
00000000 00000000 88118001 E0079009 FC3FE007 E007FC3F 9009E007 80018811
00000000 00000000 00000000 80018001 F00F8001 8001F00F 80018001 00000000
00000000 00000000 00000000 00000000 00000000 00000000 00070000 00070007
0000000E 00000000 00000000 00000000 F81F0000 0000F81F 00000000 00000000
00000000 00000000 00000000 00000000 00000000 00000000 00070000 00070007
00000000 00000000 06000200 1C000E00 70003800 C001E000 00078003 001C000E
00000000 00000000 381CF00F F81C781C B81DF81C 381FB81D 381E381F F00F381C
00000000 00000000 80018001 801F8003 8003801F 80038003 80038003 F01F8003
00000000 00000000 701CE00F 3800381C E0007000 8003C001 380E0007 F81F381C
00000000 00000000 701CE00F 3800381C C0037000 7000C003 381C3800 E00F701C
00000000 00000000 E001E000 E006E003 E018E00C F81FF81F E000E000 F803E000
00000000 00000000 001CF81F 001C001C E01F001C 7800F01F 381C3800 E00F701C
00000000 00000000 0007E003 001C000E F01F001C 381CF81F 381C381C F00F381C
00000000 00000000 1C1CFC1F 1C1C1C1C 38001C00 E0007000 8003C001 80038003
00000000 00000000 381CF00F 381C381C E007381F F81CE007 381C381C F00F381C
00000000 00000000 381CF00F 381C381C F81F381C 3800F80F 70003800 C007E000
00000000 00000000 00000000 80038003 00008003 80030000 80038003 00000000
00000000 00000000 00000000 80038003 00008003 80030000 80038003 00000007
00000000 70000000 C001E000 00078003 001C000E 000E001C 80030007 E000C001
00007000 00000000 00000000 FC3F0000 0000FC3F FC3F0000 0000FC3F 00000000
00000000 001C0000 0007000E C0018003 7000E000 E0007000 8003C001 000E0007
0000001C C0030000 781EF00F 38003818 E0007000 C001C001 00000000 C001C001
0000C001 F80F0000 1C1C1C1C 1C1C1C1C FC1CFC1C FC1CFC1C 001C001C F01F001C
0000F807 00000000 E007C003 381C700E 381C381C F81F381C 381C381C 381C381C
00000000 00000000 380EF01F 380E380E F00F380E 380EF00F 380E380E F01F380E
00000000 00000000 380EF007 001C381C 001C001C 001C001C 381C001C F007380E
00000000 00000000 700EE01F 380E380E 380E380E 380E380E 380E380E E01F700E
00000000 00000000 180EF81F 000E080E F00F300E 300EF00F 080E000E F81F180E
00000000 00000000 180EF81F 000E080E F00F300E 300EF00F 000E000E 001F000E
00000000 00000000 380EF007 381C381C 001C001C F81C001C 381C381C F807380E
00000000 00000000 701C701C 701C701C F01F701C 701CF01F 701C701C 701C701C
00000000 00000000 8003E00F 80038003 80038003 80038003 80038003 E00F8003
00000000 00000000 7000FC01 70007000 70007000 70387000 70387038 E00F7038
00000000 00000000 380E381E E00E700E 800FC00F C00F800F 700EE00E 381E380E
00000000 00000000 000E001F 000E000E 000E000E 000E000E 180E080E F81F380E
00000000 00000000 3C1E1C1C FC1F7C1F DC1DFC1F 1C1C9C1C 1C1C1C1C 1C1C1C1C
00000000 00000000 1C1C1C1C 1C1F1C1E DC1D9C1F 7C1CFC1C 1C1C3C1C 1C1C1C1C
00000000 00000000 F007E003 1C1C380E 1C1C1C1C 1C1C1C1C 380E1C1C E003F007
00000000 00000000 380EF01F 380E380E F00F380E 000EF00F 000E000E 001F000E
00000000 00000000 780FE003 1C1C380E 1C1C1C1C 7C1C1C1C F80FFC1C 3800F80F
0000FC00 00000000 380EF01F 380E380E F00F380E 700EF00F 380E380E 381E380E
00000000 00000000 381CF00F 381C381C E00F001C 3800F007 381C381C F00F381C
00000000 00000000 CC19FC1F C001C411 C001C001 C001C001 C001C001 F007C001
00000000 00000000 701C701C 701C701C 701C701C 701C701C 701C701C E00F701C
00000000 00000000 701C701C 701C701C 701C701C 701C701C E00E701C 8003C007
00000000 00000000 1C1C1C1C 1C1C1C1C 9C1C1C1C 9C1C9C1C F80FF80F 70077007
00000000 00000000 701C701C E00E701C 8003C007 C0078003 701CE00E 701C701C
00000000 00000000 701C701C 701C701C E00E701C 8003C007 80038003 E00F8003
00000000 00000000 381CF81F 70103818 C001E000 00078003 181C080E F81F381C
00000000 00000000 0007F007 00070007 00070007 00070007 00070007 F0070007
00000000 00000000 00180010 000E001C 80030007 E000C001 38007000 07001C00
00000000 00000000 7000F007 70007000 70007000 70007000 70007000 F0077000
00000000 80010000 E007C003 381C700E 00000000 00000000 00000000 00000000
00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
FF7FFF7F 00000000 001C001C 00070007 00000000 00000000 00000000 00000000
00000000 00000000 00000000 00000000 7000E00F F00F7000 701C701C D80F701C
00000000 00000000 000E001E 000E000E 380EF00F 380E380E 380E380E F01B380E
00000000 00000000 00000000 00000000 701CE00F 001C701C 701C001C E00F701C
00000000 00000000 7000F800 70007000 701CF00F 701C701C 701C701C D80F701C
00000000 00000000 00000000 00000000 701CE00F F01F701C 701C001C E00F701C
00000000 00000000 7007E003 00077007 E01F0007 0007E01F 00070007 C01F0007
00000000 00000000 00000000 00000000 701CD80F 701C701C F00F701C 7000F007
E00F701C 00000000 000E001E 000E000E 380FF00E 380E380F 380E380E 381E380E
00000000 00000000 C001C001 0000C001 C001C00F C001C001 C001C001 F80FC001
00000000 00000000 70007000 00007000 7000F003 70007000 70007000 701C7000
E007F00C 00000000 000E001E 000E000E 700E380E C00FE00E 700EE00E 381E380E
00000000 00000000 C001C00F C001C001 C001C001 C001C001 C001C001 F80FC001
00000000 00000000 00000000 00000000 9C1CF81F 9C1C9C1C 9C1C9C1C 9C1C9C1C
00000000 00000000 00000000 00000000 701CE01F 701C701C 701C701C 701C701C
00000000 00000000 00000000 00000000 701CE00F 701C701C 701C701C E00F701C
00000000 00000000 00000000 00000000 380EF01B 380E380E 380E380E 000EF00F
001F000E 00000000 00000000 00000000 E038B01F E038E038 E038E038 E000E01F
F001E000 00000000 00000000 00000000 F80FF01E 000E380F 000E000E 001F000E
00000000 00000000 00000000 00000000 301CE00F 800F301C 7018E003 E00F7018
00000000 00000000 00010000 00070003 0007F01F 00070007 70070007 E0037007
00000000 00000000 00000000 00000000 701C701C 701C701C 701C701C D80F701C
00000000 00000000 00000000 00000000 701C701C 701C701C E00E701C 8003C007
00000000 00000000 00000000 00000000 1C1C1C1C 9C1C1C1C F80F9C1C 70077007
00000000 00000000 00000000 00000000 E01CE01C 8007C00F C00F8007 E01CE01C
00000000 00000000 00000000 00000000 380E380E 380E380E F007380E E000E003
801FC001 00000000 00000000 00000000 E018E01F 8003C011 200E0007 E01F601C
00000000 00000000 8003F801 80038003 001C0007 0007001C 80038003 F8018003
00000000 C0010000 C001C001 C001C001 C001C001 C001C001 C001C001 C001C001
0000C001 00000000 C001801F C001C001 3800E000 E0003800 C001C001 801FC001
00000000 00000000 9C3B1C1F F838DC39 00000000 00000000 00000000 00000000
00000000
End DefineFont

End



This is just a code snippet, but I have tried removing the CLEARSCR sub, and replacing that with GUI DELETE 1,2,3 for the only three controls I am using in this little code snippet, but no matter what you do, once you enter in SYS for the password, the new screen is drawn and you get a numberbox you don't want.

This manifests itself as a single digit from the numberbox - number 9 in my case, lower-right hand corner, with all other numbers of the numberbox invisible. If your touch the 9, MMBASIC starts adding 9's to the end of the EXIT button.

Touch the OK button, and you get the rest of the numberbox. Type any numbers, and they are added to the end of the EXIT button. 'Ent' on the numberbox gets you out of the numberbox, and now the EXIT button is renamed to zero.

...all very odd behaviour...

If anyone has a MM+ and 7" 1963 LCD, I would love them to test this code snippet and report if they also get this rogue numberbox.

Also, if anyone sees anything obviously wrong I am doing with the code snippet, that would also be helpful if you would show me the error of my ways.

EDIT: Sometimes you DON'T see the rouge 9 on first run from clean start-up, but as soon as you press the OK button, you do....Edited by Grogster 2016-01-19
Smoke makes things work. When the smoke gets out, it stops!
 
Geoffg

Guru

Joined: 06/06/2011
Location: Australia
Posts: 3165
Posted: 03:12pm 18 Jan 2016
Copy link to clipboard 
Print this post

The problem here is that you are trying to delete the TEXTBOX while it is active on the screen. This happens in the line:
If CtrlVal(#1)="SYS" Then goto Confirm

The program should wait for the user to touch the Ent (enter) key which tells MMBasic that the user has finished with the TEXTBOX. MMBasic can then cleanup the screen and reset its internal state. Until that happens MMBasic thinks that the user is still entering the text.

I could add code in the GUI DELETE command to catch this and throw an error but it might affect other "legitimate" uses of the GUI DELETE command and would need a lot of testing - something that I don't have time for at this moment.

BASIC programs should use the pen down/up facility to work out what is happening on the screen. The following provides on way of doing it:

First, the TEXTBOX needs a unique reference number. So make the following change (in bold):
GUI textbox #11,250,175,250,50,RGB(white),RGB(black)
CtrlVal(#11)="##PASSWORD"


Then you add the following to the start of the program:
GUI INTERRUPT PenDown, PenUp

sub PenDown
if Touch(REF) = 11 then KeyPadActive = 1
end sub

sub PenUp
if Touch(LASTREF) = 11 then KeyPadActive = 0
end sub

You can then use KeyPadActive as a flag to indicate if the user has pressed Ent or not.

As the final step change the following line (the new text is in bold) and your program then works perfectly.
If CtrlVal(#11)="SYS" and KeyPadActive = 0 Then goto Confirm


As I said, MMBasic should catch errors like the above but the problem is that there are so many ways in which a control could be misused that it will take some time to close all the loopholes.

As another comment. If you are using GUI controls then everything on the screen must be a GUI control - this is important. So, for example, do not use TEXT but use GUI CAPTION instead. If you do this MMBasic will manage the screen for you including erasing and redrawing it as required. If you have to use CLS you can be confident that you are doing something wrong.

Geoff
Geoff Graham - http://geoffg.net
 
Grogster

Admin Group

Joined: 31/12/2012
Location: New Zealand
Posts: 9063
Posted: 03:30pm 18 Jan 2016
Copy link to clipboard 
Print this post

Thanks Geoff - excellent pointers!

I'm afraid that GUI coding is totally new to me, so I am running into issues cos I have not done this managing of GUI controls etc before - ever.

This is causing me some head-scratching momements like above, and it is fantastic to know that it was something I was doing wrong, rather then any kind of bug.

No offense for calling it a bug - it just so behaved like one, I did not know what was going on, and could not see what I was doing wrong.

It's all good, cos I am learning as I go.

Don't change anything if you think it is OK as is - I will learn the correct way rather then you making changes.

The CLS point in bold is well taken - I am just so used to doing that with the Maximite etc, that it has become second nature, so I need to train myself NOT to use that command for GUI work.

I will also now set about defining all the GUI controls at the start of the program as per the advanced manual page 25, and this will keep them all in one place. I will do this a section of code at a time, and bring them together.

Expect another thread on my battles with that too!
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