get edit box value

3 views (last 30 days)
DImitrios Tzelepis
DImitrios Tzelepis on 20 Dec 2015
I have created a GUI script in which the user will determine the number of edit text boxes. The user will fill these text-boxes. All the text boxes are assigned to a single callback function from which i want to read the string of these text-boxes.
f.e:
function Calback_Name(hObject, eventdata, handles)
String_Nr_1=(get(handles.tag-of-texbox-1, 'String'))
String_Nr_2=(get(handles.tag-of-texbox-2, 'String'))
However it seems that the get(handle.tag,'String') doesn not work when the text-boxes are created programmatically and not straight from GUIDE. Any idea?
  2 Comments
Jan
Jan on 20 Dec 2015
Please do not only claim, that "it doesn't work", butexplain, why you think so. Do not post pseudo code, because the problem concerns the real code. Or did you really try to call the fields "tag-of-texbox-1"?
DImitrios Tzelepis
DImitrios Tzelepis on 20 Dec 2015
Here is the for loop which creates a number of text-boxes. Their number is DT_InW_Nr_Analog which is obtained from a text box.
for Analog_Nr_Index=1:1:DT_InW_Nr_Analog
% Create tag for different boxes
DT_Analog_Calback_Names=(char(strcat('DT_Analog_Variable_Callback_',num2str(Analog_Nr_Index,'%02d'))));
% Create edit boxes
DT_Analog_Channel_Variable_Text(Analog_Nr_Index) = uicontrol(MY_GUI_FIG,'Style','edit',...
'Tag',DT_Analog_Calback_Names,...
'String','Workspace Variable Name',...
'Position',[700 DT_Analog_Height_02 200 30],'FontSize',13,...
'Interruptible','on',...
'Callback',{@DT_Analog_Calback_Name})
DT_Analog_Height_02=DT_Analog_Height_02-35;
end
Then i want to generate (automatically) the function that all these text boxes (number can be large or small according to the user input) will retur the content:
function DT_Analog_Calback_Name(hObject, eventdata,handles)
String_1=(get(handles.DT_Analog_Variable_Callback_01, 'String'))
String_2=(get(handles.DT_Analog_Variable_Callback_02, 'String'))
.
.
.
Then i get the following error:
Reference to non-existent field 'DT_Analog_Variable_Callback_01'.
However i tried to call the same way other edit text boxes which I generated in GUIDE, and they return their string. I seems that I cannot call the string from the text boxes I created programmatically.

Sign in to comment.

Answers (1)

Jan
Jan on 20 Dec 2015
Has the handles struct been modified after the callbacks are created? Then:
function Calback_Name(hObject, eventdata)
handles = guidata(hObject);
String_Nr_1 = get(handles.texbox1, 'String');
String_Nr_2 = get(handles.texbox2, 'String');

Categories

Find more on Migrate GUIDE Apps in Help Center and File Exchange

Products

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!