필터 지우기
필터 지우기

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

조회 수: 35 (최근 30일)
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
Rahul
Rahul 2023년 1월 3일
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 2023년 1월 6일
@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.

댓글을 달려면 로그인하십시오.

채택된 답변

Geoff Hayes
Geoff Hayes 2022년 12월 21일
편집: Geoff Hayes 2022년 12월 21일
@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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Entering Commands에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by