How do you transfer information in a GUI? For example, If the user types in (-4) in a text box i want to use a text/edit box to say 'Please enter a positive number.' I don't know how to transfer the information from one function to another. PLEASE HELP!

 Respuesta aceptada

Paulo Silva
Paulo Silva el 23 de Abr. de 2011

2 votos

The GUIs built by GUIDE use the handles structure to share the handles for all the GUI objects, for example:
handles.edit1 %this is the handle for one edit box, edit1 is the box name
get(handles.edit1,'String') %gives you what's inside the edit box 1
%This will put your message on one text box
set(handles.text1,'String','Please enter a positive number.')
For your example you can edit the edit box callback and add a detection, for example:
if str2double(get(handles.edit1,'String'))<0
%Warn the user about the negative input
set(handles.edit1,'String','0') %put zero (default value) on the edit box
end

Más respuestas (0)

Categorías

Más información sobre Just for fun en Centro de ayuda y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by