Is there a way to subscript a textbox in a GUI so that the same code does not have to be written for every callback?

I have written a GUI in which I have 60 text boxes. The text boxes have tags like txt_s01, txt_s02, etc. Within the callback for each textbox, I have code that checks the validity of the entry and makes adjustments if necessary. The last two lines of the callback read like this:
set(handles.txt_s01,'String',num);
guidata(hObject,handles)
or
set(handles.txt_sr02,'String',num);
guidata(hObject,handles)
etc. I would like to be able to do what I can do in Visual Basic, which allows the user to create a textbox array, wherein all of the textboxes can be referred by one set of event callbacks, similar to this:
Private Sub txt_space_LostFocus(Index As Integer)
'
' Change the information
'
delta_az(Index) = Val(txt_space(Index).Text)
delta_az(Index) = amax(amin(delta_az(Index), 100), -100)
delta_az(Index) = delta_az(Index)
txt_space(Index).Text = rformat(delta_az(Index))
End Sub
Is there a succinct way to do this in a Matlab GUI? Thank you.

Answers (1)

Even better! Have just one callback for all of the pushbuttons
txt_num_Callback(etc.)
And just use the hObject value which is the handle to source pushbutton:
set(hObject,'String',num)
And as a warning:
When you guidata, you typically want to point to the figure since hObject changes depending on the caller:
guidata(handles.figure1,handles); %where "figure1" is the tag of the figure

Categories

Find more on Interactive Control and Callbacks in Help Center and File Exchange

Products

Tags

Asked:

on 4 Mar 2013

Community Treasure Hunt

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

Start Hunting!