Borrar filtros
Borrar filtros

Print Multiple Lines into TextArea Automatically without mentioning the Array (MATLAB App Designer)

28 visualizaciones (últimos 30 días)
Hello,
I am trying to create like a message box into app designer using the Text Area component. For example if the user enter the Name and LastName it displays 'Name and LastName Entered successfully'. Else the Text Area displays 'Information Not Provided'. So now when the user selects Gender from drop down box it should displays 'Gender as Male selected'. Text is displayed into the Text Area when a Button is clicked. The button has a functionality to check whether the textField is empty or not empty. And to check whether the textField is empty its done with a help of function checkNames(app). To check the selected Gender from the dropDown Menu I am using a Switch case and the switch case is evaluated using the function checkGender(app). Is there a way so that i dont have to define .Value{1}, .Value{2} .... Thank You
Code
methods (Access = private)
function checkNames(app)
if ~(isempty(app.EditField_Name.Value) || isempty(app.EditField_LastName.Value))
app.MessageBoxTextArea.Value{1} = 'Name and LastName Entered successfully';
else
app.MessageBoxTextArea.Value{1} = 'Information Not Provided';
uiwait(app.checkNames);
end
end
function checkGender(app)
switch app.DropDown_Gender.Value
case 'Male'
app.MessageBoxTextArea.Value{2} = 'Gender as Male Selected';
case 'Female'
app.MessageBoxTextArea.Value{2} = 'Gender as Female Selected';
otherwise
app.MessageBoxTextArea.Value{2} = 'Gender as Others Selected';
end
end
end
% Callbacks that handle component events
methods (Access = private)
% Button pushed function: Button
function ButtonPushed(app, event)
checkNames(app);
checkGender(app);
end
end
  4 comentarios
Rahul
Rahul el 3 de En. de 2023
Thank you @Geoff Hayes. It worked for me! Can we also add the functionality of changing the text colour? for example if its 'Data Entered Sucessfully' it should display in the text area with Green as the font colour. And when it is an error it is displayed with a font colour of Red?
Geoff Hayes
Geoff Hayes el 6 de En. de 2023
@Rahul - I don't think you can do that for individual lines. There may be some undocumented means of doing that sort of thing (wrapping text in html tags?) but I'm not sure how to do that.

Iniciar sesión para comentar.

Respuesta aceptada

Geoff Hayes
Geoff Hayes el 21 de Dic. de 2022
Editada: Geoff Hayes el 21 de Dic. de 2022
@Rahul - you could add a helper function/method that will add the text for you at the correct index. For example, that function may look like
function addMessageToMessageBox(app, msg)
x = length(app.MessageBoxTextArea.Value);
app.MessageBoxTextArea.Value{x+1} = msg;
end
and then your code would become
function checkNames(app)
if ~(isempty(app.EditField_Name.Value) || isempty(app.EditField_LastName.Value))
addMessageToMessageBox(app, Name and LastName Entered successfully');
else
addMessageToMessageBox(app, 'Information Not Provided');
uiwait(app.checkNames);
end
end
function checkGender(app)
switch app.DropDown_Gender.Value
case 'Male'
addMessageToMessageBox(app, 'Gender as Male Selected');
case 'Female'
addMessageToMessageBox(app, 'Gender as Female Selected');
otherwise
addMessageToMessageBox(app, 'Gender as Others Selected');
end
end

Más respuestas (0)

Categorías

Más información sobre Develop uifigure-Based Apps en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by