Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Editboxes in a Script

Asked by James Tammen on 13 Sep 2013

I have a script to run a GUI menu in order to tie together a list of different scripts/functions so that they can run overnight without manual input. I already have a pushbutton and several checkboxes that are functional.

close all
if ~exist('utilcode'); utilcode='';end
positiona=[30 550 120 20];
utility=uicontrol('Style','edit','string','<utilcode>','position',positiona,'Callback',utilcode);
position2=[30,475,120,20];
BuildHr8=uicontrol('Style','checkbox','string','Build Hr8 Files','position',position2);
set(BuildHr8,'Callback','Build1=1;')

I am able to get a good return on the checkboxes, but the editboxes return a blank matrix.

I tried doing this with functions, but the variables would be replaced with random numbers (not to mention moving variables became a headache.

1 Comment

Arthur on 13 Sep 2013

How to you read the the String from the textbox?

James Tammen

Products

No products are associated with this question.

4 Answers

Answer by Image Analyst on 13 Sep 2013

Did you try the get() function to retrieve the current contents of the edit box?

contentsOfEditbox = get(utility, 'String');

0 Comments

Image Analyst
Answer by James Tammen on 16 Sep 2013
Edited by Walter Roberson on 16 Sep 2013

I tried using functions such as

utility=uicontrol('Style','edit','string','<utilcode>','position',positiona,'Callback',@h_utility);
Execute=uicontrol('Style','push','string','GO','position',position4,'Callback',@h_GO);
function h_utility(hObject,eventdata,Convert,Build,Update)
utilcode=get(hObject,'String')
function h_GO(utilcode,ReadFilesAfterDate,ReadSubdirs,Convert,Build,Update)
close all
utilcode=get(h_utility,'String')

The function h_utility recognizes the input (i.e. I type in abc, it returns abc), but in function h_GO it returns a number in the utilcode input as 5.0037 and the get() function returns an error of too many input arguments (which doesn't make sense to me).

5 Comments

James Tammen on 19 Sep 2013

GUIDE creates a reference figure and our network does not pass on figure files to individual work stations.

Jan Simon on 19 Sep 2013

Figures are simple files in the MAT format, which contain a struct. I cannot believe that a network would refuse to transport them.

I do not use GUIDE. Over the years I've created a neat set of functions which allow a finer control and more details than the automatically created GUIDE code.

Image Analyst on 19 Sep 2013

Yeah, that seems weird to me that your intranet won't let you load a .fig file. If not, then you're stuck "rolling your own" via a boatload of tedious m-file statements.

James Tammen
Answer by Walter Roberson on 16 Sep 2013
get(h_utility,'String')

is going to run the function h_utility and take its return value as the list of handles whose String property is to be fetched. But the function h_utility not defined to return any value. That would lead to an error.

Note that when you execute h_utility, the variable you write to, utilcode, is a local variable, so the value of that variable is discarded after the get()

Perhaps the above is not your actual code?

2 Comments

James Tammen on 16 Sep 2013

This is my actual code (there are two more edit boxes, but they are structured the same way).

I don't fully understand, how do I set up a return for h_utility and/or editbox utility?

Walter Roberson on 16 Sep 2013

Please look in the file exchange for the 41 Complete Sample GUIs contribution.

Walter Roberson
Answer by Arthur on 16 Sep 2013

You need to pass on the handle of your textbox to the function that has to read out the textbox. The common way to do this is by creating a handles struct, containing all the handles of your GUI.

Easy methods to do this is by using the function guidata, or by using getappdata/setappdata.

2 Comments

James Tammen on 20 Sep 2013

I tried rewriting my code and simplyfing what I need to do. This is all I have now:

function Test1
close all
WxHrProcessor = figure('Toolbar','none');
myhandles = guihandles(WxHrProcessor); 
positiona=[5 300 120 20];
myhandles.utility=uicontrol('Style','edit','string','<utilcode>','position',positiona,'Callback',@h_utility);
guidata(WxHrProcessor,myhandles);
uicontrol('style','push','callback',@My_Callback);
function h_utility(hObject,eventdata)
myhandles = guidata(gcbo);
myhandles.utility=get(hObject,'String')
function My_Callback(hObject,eventdata)
myhandles = guidata(gcbo);
Utilcode=myhandles.utility
guidata(gcbo,myhandles)
myhandles

Yet on the first function the guidata is able to save my input and the secound function somehow converts it to 155.0142. This is my first GUI without Guide, so you are going to need to spell it out for me.

Image Analyst on 20 Sep 2013

See how hard it is if you're going to do all the gory details yourself? Anyway, please be specific about what function is "the first function", what function is "the secound function", and exactly what gets converted to 155.0142 (which looks just like the value of a handle.)

Arthur

Contact us