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 : GUI Control
Page 1 of 2 | |||||
Author | Message | ||||
palcal Guru Joined: 12/10/2011 Location: AustraliaPosts: 1804 |
Still having problems with this. Can some one tell me what is wrong with my code. OPTION EXPLICIT COLOUR RGB(WHITE), RGB(BLACK) ' reference numbers for the controls are defined as constants CONST numEntry = 1 DIM x AS INTEGER CLS GUI INTERRUPT TouchDown, TouchUp Start: GUI NUMBERBOX numEntry, 50,40,90,40,RGB(YELLOW),RGB(64,64,64) CtrlVal(numEntry) = "##ENTER" DO LOOP until X>0 Print "Number = ";x Pause 3000 Goto Start SUB TouchDown SELECT CASE TOUCH(REF) ' find out the control touched CASE numEntry PRINT "entering a number" END SELECT END SUB ' interrupt routine when the touch is removed SUB TouchUp SELECT CASE TOUCH(LASTREF) ' use the last reference CASE numEntry ' was it the numEntry box x = CTRLVAL(numEntry) PRINT x END SELECT END SUB Result. Thanks....Paul. "It is better to be ignorant and ask a stupid question than to be plain Stupid and not ask at all" |
||||
Zonker Guru Joined: 18/08/2012 Location: United StatesPosts: 761 |
When you first run things go ok until you force the "goto start" You then try to "re-declare" the creation of your numberbox GUI object... You can't do that. The program will "force stop" because you attempt to do so... Just stay inside the Do-Loop after the GUI objects are created... |
||||
Grogster Admin Group Joined: 31/12/2012 Location: New ZealandPosts: 9066 |
Completely agree with Zonker. You can't re-define controls that have already been defined - that is why it is moaning at the console with the error. Zonker is also right about staying within the loop. Don't despair - GUI programming takes a bit of head-scratching if you have not done it before. Smoke makes things work. When the smoke gets out, it stops! |
||||
palcal Guru Joined: 12/10/2011 Location: AustraliaPosts: 1804 |
OK understand, but if I declare it at the start of the code, how do I get the NUMBERBOX to appear every time I want to use it. If it is not asking too much could you fix my code and post it back. Paul. "It is better to be ignorant and ask a stupid question than to be plain Stupid and not ask at all" |
||||
TassyJim Guru Joined: 07/08/2011 Location: AustraliaPosts: 5912 |
Have a play with GUI HIDE and GUI SHOW Create all the controls and hide the ones that are for later when you want to see the control GUI SHOW Jim VK7JH MMedit MMBasic Help |
||||
palcal Guru Joined: 12/10/2011 Location: AustraliaPosts: 1804 |
Ok tried the HIDE and SHOW but now I get an error with x = CtrlVal(numEntry) Error.. Expected a number Paul. "It is better to be ignorant and ask a stupid question than to be plain Stupid and not ask at all" |
||||
palcal Guru Joined: 12/10/2011 Location: AustraliaPosts: 1804 |
I have worked on this on and off for over a month, I have read and re read the Manual real Geoff's example code but I just can't get it right. Paul. "It is better to be ignorant and ask a stupid question than to be plain Stupid and not ask at all" |
||||
palcal Guru Joined: 12/10/2011 Location: AustraliaPosts: 1804 |
This is the code at the moment. Option EXPLICIT Colour RGB(WHITE), RGB(BLACK) ' reference numbers for the controls are defined as constants Const numEntry = 1 Dim x As INTEGER CLS GUI INTERRUPT TouchDown, TouchUp Start: GUI NUMBERBOX numEntry, 50,40,90,40,RGB(YELLOW),RGB(64,64,64) GUI Hide numEntry START: Do GUI Show numEntry CtrlVal(numEntry) = "##ENTER" Loop Until X > 0 Print "Number = ";x Pause 3000 GoTo Start Sub TouchDown Select Case Touch(REF) ' find out the control touched Case numEntry Print "entering a number" End Select End Sub ' interrupt routine when the touch is removed Sub TouchUp Select Case Touch(LASTREF) ' use the last reference Case numEntry ' was it the numEntry box x = CtrlVal(numEntry) End Select End Sub I am just trying to enter a number and print it over and over.. When I run this code the NUMBERPAD appears but the number does not enter when I hit enter. Paul "It is better to be ignorant and ask a stupid question than to be plain Stupid and not ask at all" |
||||
BobD Guru Joined: 07/12/2011 Location: AustraliaPosts: 935 |
Paul You have the labels START: and Start: in your program. That may confuse the interpreter. Bob |
||||
BobD Guru Joined: 07/12/2011 Location: AustraliaPosts: 935 |
Paul Instead of [code] START: Do GUI Show numEntry CtrlVal(numEntry) = "##ENTER" Loop Until X > 0 Print "Number = ";x Pause 3000 GoTo Start [/code] What about this [code] Do Do GUI Show numEntry CtrlVal(numEntry) = "##ENTER" Loop Until X > 0 Print "Number = ";x Pause 3000 Loop [/code] It gets rid of the GOTO Bob |
||||
palcal Guru Joined: 12/10/2011 Location: AustraliaPosts: 1804 |
The first Start: was left there my mistake. I will try your code and see what happens. I probably am stupid but this GUI stuff is very confusing. Paul. "It is better to be ignorant and ask a stupid question than to be plain Stupid and not ask at all" |
||||
TassyJim Guru Joined: 07/08/2011 Location: AustraliaPosts: 5912 |
This might be what you are after. I removed the first START: The SHOW and HIDE aren't really needed for this simple program but I expect you will need them in the final code. You had the line CtrlVal(numEntry) = "##ENTER" in the middle of the DO LOOP I cleared the X value to zero so it waits for a new entry. Without resetting X, the code kept going through the main loop. Jim VK7JH MMedit MMBasic Help |
||||
palcal Guru Joined: 12/10/2011 Location: AustraliaPosts: 1804 |
Thanks a lot Jim, that works. Thanks to every one who chimed in, don't know what I would do without you. Now to see if I can implement that into my final code. Watch this space!!! Paul. "It is better to be ignorant and ask a stupid question than to be plain Stupid and not ask at all" |
||||
Grogster Admin Group Joined: 31/12/2012 Location: New ZealandPosts: 9066 |
[Quote=Paul]I probably am stupid but this GUI stuff is very confusing.[/Quote] You are NOT stupid. If it makes you feel any better, I was tearing my hair out when I first started working with GUI controls. They behave in and of themselves, quite differently to how you expect a normal sequential program to run, and so you have to deal with, and think about how MMBASIC is treating all these various interrupts causing the code to hop about the place in a somewhat random fashion - or so it seems at first, and yes - confusing as hell..... HOWEVER, it DOES get easier the more you play with GUI, and as more and more members here start to play with the GUI controls ideas, you will get more and more people chiming in with ideas. For right now, GUI controls are still reasonably new to the MMBASIC user, and many people are probably frightened off by their complexity to some extent. But hang in there - well worth the effort to learn the GUI stuff! Smoke makes things work. When the smoke gets out, it stops! |
||||
palcal Guru Joined: 12/10/2011 Location: AustraliaPosts: 1804 |
Thanks Grogs, Geoff has done a wonderful job on the manuals and I don't want to knock but nowhere to my knowledge does it explain that the control can only be used once and once removed from the screen will throw the 'already in use' error when you bring it back up. I understand now how to hide and show so should be OK. I don't know if this would work but could the CLS command also hide the control then when needed just use GUI show. Paul. "It is better to be ignorant and ask a stupid question than to be plain Stupid and not ask at all" |
||||
TassyJim Guru Joined: 07/08/2011 Location: AustraliaPosts: 5912 |
From the Micromite Plus manual under "Using basic drawing commands" When I started programming GUIs in Windows, I hated it. I still hate it at regular intervals. I haven't really started anything serious with micromite GUIs so I will be looking for some hair to tear out too. Jim VK7JH MMedit MMBasic Help |
||||
Phil23 Guru Joined: 27/03/2016 Location: AustraliaPosts: 1664 |
Hi Paul, Yes CLS does seem to act the same as GUI HIDE ALL. What worked for me was setting up pages after I defined the controls. I defined 5 pages, 1,2,3,4 & 9 and are always displaying two at a time. As in Page 1,9 Page 2,9 etc. Have a look in this post for some ideas. Ignore the 4th page as I'm breaking rules in that one & it could end up disastrous. It's still work in progress & I'm now looking at it again after a 6 month break. I just stuck a quick video of it up on YouTube. Cheers Phil. Edit:- @Grogster.... Took me 20 minutes to finish this post including deciding to add the video. Lol, wasn't intending on repeating what you said. |
||||
palcal Guru Joined: 12/10/2011 Location: AustraliaPosts: 1804 |
I was using CLS but then was re defining the control instead of using GUI show. Thus getting an error. I am getting somewhere finally and have the NUMBERBOX working well Thanks to all who have helped. Paul. "It is better to be ignorant and ask a stupid question than to be plain Stupid and not ask at all" |
||||
Grogster Admin Group Joined: 31/12/2012 Location: New ZealandPosts: 9066 |
Think of defining GUI's as the same kind of idea as defining a variable - you only ever do it once, usually at the top of your program. If you define a variable with the DIM command, and then try to define it again later on, this will throw an error. GUI controls are exactly the same in that respect. The only exception to that rule, is if you use the GUI DELETE command to delete a certain control and reference number. If you had control #5, and you deleted it somewhere in your code, you COULD then re-define it as #5 later. This is probably not good practise though, and all GUI controls PROBABLY should be declared at the start of the program, and left alone - even if you only use that control once or twice in your code. Define it, and move along. @ Phil23 - I love the GUI pages. They are awesome. With the simple PAGE command, you can select the controls you want to be seen, and hide all the others. If you have lots and lots of controls(I'm currently using about 150), breaking them up into pages makes drawing each screen of controls so simple. I love GUI pages in MMBASIC... Smoke makes things work. When the smoke gets out, it stops! |
||||
palcal Guru Joined: 12/10/2011 Location: AustraliaPosts: 1804 |
Thanks Grogs, I have my head around it now. All GUIs defined at the start with the rest of the setup. Then CLS and GUI SHOW. My code is working now. I also found when using Ghost text in the NUMBERBOX that "##" + String$ works. Paul. "It is better to be ignorant and ask a stupid question than to be plain Stupid and not ask at all" |
||||
Page 1 of 2 |
Print this page |