This exact function works for my 1st list box i turned off 'enable' and set a condition that forces a selection to be made from list box so the push button is enable, but that isnt working for the other pushbuttons. i have attached the code
function ListBox_3ValueChanged(app, event)
value = app.ListBox_3.Value;
if strcmp(app.ListBox.Value,'Female')|| strcmp(app.ListBox.Value,'Male')||strcmp(app.ListBox.Value,'Intersex')||strcmp(app.ListBox.Value,'Non-conforming')...
||strcmp(app.ListBox.Value,'Gender-fluid')||strcmp(app.ListBox.Value,'Genderqueer')||strcmp(app.ListBox.Value,'Transgender');
set(app.NEXTButton_2,'Visibility','on')
set(app.NEXTButton_2,'Enable','on');
end % simple loop that allows the push button to stay disabled until the person selects an option.
end

4 Comments

Your code looks at the selection in ListBox_3 and enables the NextButton_2 and makes it visible if the ListBox_3 is one of those choices. It should work but I don't know what you want it to do or why it doesn't work in some cases. Attach your .mlapp file and tell us what to select/change to demonstrate your problem after you read this:
I am not sure why it only works for the 1st tab and not the 2nd. The are under the same function, but for different lust box and i have checked several times to make sure the push button is turned off, but it still doesnt work.
The part to select or change would be:
function ListBox_3ValueChanged(app, event)
value = app.ListBox_3.Value;
if strcmp(app.ListBox.Value,'Female')|| strcmp(app.ListBox.Value,'Male')||strcmp(app.ListBox.Value,'Intersex')||strcmp(app.ListBox.Value,'Non-conforming')...
||strcmp(app.ListBox.Value,'Gender-fluid')||strcmp(app.ListBox.Value,'Genderqueer')||strcmp(app.ListBox.Value,'Transgender');
set(app.NEXTButton_2,'Visibility','on')
set(app.NEXTButton_2,'Enable','on');
end % simple loop that allows the push button to stay disabled until the person selects an option.
end
If i can figure out why this isn't working then i can make adjustment to my other tabs because they have a similar format
I have read the tutorial, thank you for attaching that.
I can't even get it to display the tabs. When I run it, they're chopped off. Look:
You see the tabs in Design View but when you actually run it the top part of the figure is chopped off!
Nwasinachi
Nwasinachi on 22 Nov 2022
Edited: Nwasinachi on 22 Nov 2022
I just made a modification it should run well now and resize decently
They are that way because of a resizing issue. App designer has a very complicated sizing criteria, so i am unable to use percentages to size the page and using pixels causes my app to lose pushbuttons (not visible on the screen when it is resized). i have been trying different codes to fix that issue but StartFcn makes the other functions non-functional so i had to remove that line of code.
You can still run the app. if you click on NEXT it should proceed to the next tab. If it isnt working please let me know.

Sign in to comment.

 Accepted Answer

Voss
Voss on 22 Nov 2022
Edited: Voss on 22 Nov 2022
NEXTButton_2 has no Callback (i.e., no ButtonPushedFcn) assigned to it.

11 Comments

Voss
Voss on 22 Nov 2022
Edited: Voss on 22 Nov 2022
Also, rather than checking for each possible selection with if ... || ... || ... , you can use isempty to determine whether a selection is made. (And if you set Enable to 'on' under some condition, you usually want to set it to 'off' under the opposite condition.)
So your code might look like this:
value = app.ListBox.Value;
if isempty(value)
set(app.NEXTButton,'Enable','off');
else
set(app.NEXTButton,'Enable','on');
end
Or even more simply:
set(app.NEXTButton,'Enable',~isempty(app.ListBox.Value));
Or equivalently:
app.NEXTButton.Enable = ~isempty(app.ListBox.Value);
Hi. i have fixed that and the problem is still there, the push button doesnt get enabled after a selection is made on the list
Voss
Voss on 22 Nov 2022
Edited: Voss on 22 Nov 2022
Also, in ListBox_3ValueChanged, you are checking the value of app.Listbox, not the value of app.ListBox_3:
function ListBox_3ValueChanged(app, event)
value = app.ListBox_3.Value
if strcmp(app.ListBox.Value,'Female')|| strcmp(app.ListBox.Value,'Male')||strcmp(app.ListBox.Value,'Intersex')||strcmp(app.ListBox.Value,'Non-conforming')...
||strcmp(app.ListBox.Value,'Gender-fluid')||strcmp(app.ListBox.Value,'Genderqueer')||strcmp(app.ListBox.Value,'Transgender');
set(app.NEXTButton_2,'Enable','on');
end % simple loop that allows the push button to stay disabled until the person selects an option.
end
and app.Listbox will never satisfy any of those Gender selection conditions because it is the Age listbox.
Anyway, you can change it to be analogous to the code in my previous comment:
function ListBox_3ValueChanged(app, event)
app.NEXTButton_2.Enable = ~isempty(app.ListBox_3.Value);
end
Same for ListBox_4ValueChanged:
function ListBox_4ValueChanged(app, event)
app.NEXTButton_3.Enable = ~isempty(app.ListBox_4.Value);
end
And you may consider setting the listboxes' default selections to empty so that the user doesn't have to deselect/reselect or change selection just to enable the button, in case their selection happens to be the default value. (Either that, or run the Callbacks on startup one time to synchronize the buttons with the listbox selections.)
Thank you. i didnt even notice that mistake and i have been working on it for almost 2 weeks.
@Voss APP designer doesnt allow me to set the value to {} or [] in the component browser. it gives an error stating that the value must be an element defined in Items property.
In that case, you can try setting the listboxes' values to empty in a startupFcn, or try the other option I mentioned, which is running the listboxes' callbacks from the startupFcn.
In either case, first assign a startupFcn for the figure in Component Browser, and then define it like this to set the values to empty (no initial selection):
% Code that executes after component creation
function startupFcn(app)
app.ListBox.Value = {};
app.ListBox_3.Value = {};
app.ListBox_4.Value = {};
end
or like this to run the callbacks (button enable state consistent with initial selection):
% Code that executes after component creation
function startupFcn(app)
ListBoxValueChanged(app)
ListBox_3ValueChanged(app)
ListBox_4ValueChanged(app)
end
I've tested both ways and they seem to work, so it's just up to you to decide how the app should function.
Thank you so much. This works really well and i can apply it to the rest of my project.
I have a question, Related to startupFcn, do you think it is possible to create a struct array and include field in this area? so it is created before the figure is made?
You're welcome!
I'm not sure what you mean by "include field in this area". Can you explain? What is this struct array meant to be used for?
So the list boxes that i have posted in this thread are components of User Interface i am creating.
The user is supposed to make a selection as they go through each tab.
The struct array is there so i can collect those inputs(answers) which are either from the radio buttons or list boxes, because i will have to compute some statistical analysis later, but if i am unable to have the inputs saved for each user then this analysis is almost impossible to do.

Sign in to comment.

More Answers (0)

Categories

Find more on Develop Apps Using App Designer in Help Center and File Exchange

Products

Release

R2022b

Asked:

on 22 Nov 2022

Commented:

on 22 Nov 2022

Community Treasure Hunt

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

Start Hunting!