Home
JAQForum Ver 24.01
Log In or Join  
Active Topics
Local Time 05:37 13 Nov 2025 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 : Mental jog needed for MMBasic

Author Message
OA47

Guru

Joined: 11/04/2012
Location: Australia
Posts: 1013
Posted: 04:21am 11 Aug 2019
Copy link to clipboard 
Print this post

My mind has blanked on this one and re-reading the documentation hasn't helped. How do I retrieve the newly entered string from a GUI TextBox after the ENT key has been pressed?

OA47
 
Grogster

Admin Group

Joined: 31/12/2012
Location: New Zealand
Posts: 9755
Posted: 04:43am 11 Aug 2019
Copy link to clipboard 
Print this post

Just read the control value after the GUI control has closed.

So, if you had a TextBox called TB(for textbox), once you press ENT on the GUI control and the on-screen keyboard is erased, whatever you typed will be held in the control-value for that GUI element.

So:

STRING$=CtrlVal(TB)

Done.
Smoke makes things work. When the smoke gets out, it stops!
 
OA47

Guru

Joined: 11/04/2012
Location: Australia
Posts: 1013
Posted: 05:02am 11 Aug 2019
Copy link to clipboard 
Print this post

Thanks G.
That is how I remember it but I think my problem is a missing step. After typing in the new string to the textbox I issue a GUI TextBox Cancel which elimiates the keypad but the TextBox still remains with CtrlVal=""

OA47

Further to my woes I thought I would see how a NumberBox would react and no matter what Ref number I give it I receive an error at run time that the GUI ref number is in use.
Edited 2019-08-11 15:21 by OA47
 
KeepIS

Guru

Joined: 13/10/2014
Location: Australia
Posts: 1945
Posted: 05:49am 11 Aug 2019
Copy link to clipboard 
Print this post

  OA47 said  Thanks G.
That is how I remember it but I think my problem is a missing step. After typing in the new string to the textbox I issue a GUI TextBox Cancel which elimiates the keypad but the TextBox still remains with CtrlVal=""

OA47

Further to my woes I thought I would see how a NumberBox would react and no matter what Ref number I give it I receive an error at run time that the GUI ref number is in use.


Random thoughts.

Using GUI TEXTBOX CANCEL will cancel any text entered into the textbox.

GUI reference number in use: Causes sometimes related to how the program is loaded, edited and run.

Mike.
NANO Inverter: Full download - Only Hex Ver 8.1Ks
 
OA47

Guru

Joined: 11/04/2012
Location: Australia
Posts: 1013
Posted: 04:20am 12 Aug 2019
Copy link to clipboard 
Print this post

I have been able to upgrade the ARMmite F4 to what I think is the latest version of MMBasic that Peter has released (5.0508) but I still have the issue with the error GUI reference number is in use, no matter what number I use for the 6th element.

If some kind person with a similar unit could test this code for me it would be greatly appreciated. Also if anyone could correct my code for reading the entered text of the ##Filename TEXTBOX.

'******************************************************************************
'* TEST PROGRAM FOR STM32F407VET6 WITH ILI9341_16 *
'* *
'******************************************************************************
'MM.VER=5.0508
'OPTION PRE-REQUISITES
'Option LCDPanel ILI9341_16, Landscape
'Option Touch 51, 34 (PB12, PC5)

CLS
Dim Clock$
Dim String$
SetPin PA6,Dout
SetPin PA7,Dout
Pause 500
Pin(PA6)=1
Pause 500
Pin(PA7)=1

Const ON = 1
Const OFF = 2
Const SVE = 3
Const LED = 4
Const TBOX = 5
Const AMNT = 60
GUI INTERRUPT PenDown

GUI BUTTON ON, "ON", 5, 5, 30, 20, RGB(black), RGB(green)
GUI BUTTON OFF, "OFF", 38, 5, 30, 20, RGB(white), RGB(red)
GUI BUTTON SVE, "Save",10, 150,50,20,RGB(black), RGB(yellow)
GUI LED LED,"ACTIVE", 95, 20, 15, RGB(red)
GUI BUTTON AMNT, "Amount",10,180,50,20,RGB(White),RGB(Blue)
'
Do
Clock$=Time$+" "+Date$
Text 165,0,Clock$,,1
Loop

Sub PenDown
Select Case Touch(REF)
Case ON
CtrlVal(LED) = 1
Pin(PA6)=0
Case OFF
CtrlVal(LED) = 0
Pin(PA6)=1
Case SVE
SaveData
Case AMNT
EntAmnt
End Select
End Sub

Sub SaveData
GUI TextBox TBOX,10,120,120,20
CtrlVal(TBOX) = "##Filename"
Pin(PA7)=0
String$=CtrlVal(TBOX)
Print " CtrlVal(TBOX)=";String$
GUI TextBox Cancel
Pin(PA7)=1
End Sub

Sub EntAmnt
GUI NumberBox AMNT,10,120,120,20
GUI NumberBox Cancel
Print "CtrlVal(AMNT)=";CtrlVal(AMNT)
End Sub


OA47
 
KeepIS

Guru

Joined: 13/10/2014
Location: Australia
Posts: 1945
Posted: 06:44am 12 Aug 2019
Copy link to clipboard 
Print this post

Just running out the door as I saw your post, just a quick glance at the code but it looks like you are creating GUI elements inside of procedures, so each time it's called it tries to make a new GUI with the same number and fails.

To keep it simple, all GUI controls should be declared at the top of the program with the others GUI controls.

Use a different page to declare GUI controls that only show when a procedure is run, simply switch pages to display different control sets.

If you want all controls showing then just move the following to the top with the rest of the GUI.

GUI NumberBox AMNT,10,120,120,20

GUI TextBox TBOX,10,120,120,20

AND you are using Const AMNT = 60 for two GUI controls.

GUI BUTTON AMNT, "Amount",10,180,50,20,RGB(White),RGB(Blue)
GUI NumberBox AMNT,10,120,120,20

change the last 3 items above and it should run.
NANO Inverter: Full download - Only Hex Ver 8.1Ks
 
OA47

Guru

Joined: 11/04/2012
Location: Australia
Posts: 1013
Posted: 07:26am 12 Aug 2019
Copy link to clipboard 
Print this post

Thanks KeepIS, I see the double use of AMNT. If I set up the NumberBox and the TextBox at the start of the program, do I HIDE them and then Show and Hide within the subroutine?

OA47
 
KeepIS

Guru

Joined: 13/10/2014
Location: Australia
Posts: 1945
Posted: 08:15am 12 Aug 2019
Copy link to clipboard 
Print this post

Yes, a few ways to do this, but GUI HIDE / SHOW will work. For more advanced GUI pages where you instantly switch the screen GUI display controls use GUI SETUP, Geoff shows some examples in the Micromite Plus manual. There is a lot of power behind the GUI controls, especially with page switching combined with HIDE / SHOW and DISABLE / ENABLE commands.

Mike.
NANO Inverter: Full download - Only Hex Ver 8.1Ks
 
KeepIS

Guru

Joined: 13/10/2014
Location: Australia
Posts: 1945
Posted: 08:41am 12 Aug 2019
Copy link to clipboard 
Print this post

BTW to display the contents of the Textbox you need something like this:

Add a PenUP interrupt to catch the enter key press on the Textbox. The Textbox will close.

Remove GUI TextBox Cancel.

For the purpose of a simple example, move the Display for the Textbox to PenUP.


GUI INTERRUPT PenDown, PenUP

sub PenUP
if touch(lastref) = TBOX then
String$=CtrlVal(TBOX)
Print " CtrlVal(TBOX)=";String$
endif
end sub

NANO Inverter: Full download - Only Hex Ver 8.1Ks
 
OA47

Guru

Joined: 11/04/2012
Location: Australia
Posts: 1013
Posted: 10:16pm 12 Aug 2019
Copy link to clipboard 
Print this post

Thank you KeepIs, I think I have my head around it again the PENUP was the prompt I needed to aquire the modified info. I did have a fair grasp of the GUI commands 18 months ago but it seems that part of my memory has evaded the refresh cycles.

Best I start writing notes in the hope that I can find them again when I need them.

OA47
 
Grogster

Admin Group

Joined: 31/12/2012
Location: New Zealand
Posts: 9755
Posted: 11:00pm 12 Aug 2019
Copy link to clipboard 
Print this post

GUI programming is really confusing and quite hard when you are new to it, cos all the GUI stuff is being handled in the background by the interpreter, and all at random times during code execution. This is counter-intuitive to 'Normal' programming where you just do everything step-by-step.

I lost lots of hair trying to work out how to do GUI stuff when I first started with it. Like most of the more powerful features though, it is worth the effort, as MMBASIC is very powerful when you start using the GUI controls.

KeepIS is exactly right when he said to declare all your GUI stuff right at the top of your code. GUI controls are global to the code. Think of the GUI controls as a kind of CONST or DIM command, where you would declare these right at the top of your code, BEFORE the main loop. ALL GUI controls, used ANYWHERE in your code.

Hang in there. GUI controls are fantastic, once you learn how to use them.
Smoke makes things work. When the smoke gets out, it stops!
 
Print this page


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

The Back Shed's forum code is written, and hosted, in Australia.
© JAQ Software 2025