App Designer Uneditable Code
25 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Sebastian Caceres
am 12 Jan. 2021
Beantwortet: Athrey Ranjith Krishnanunni
am 16 Jan. 2021
Hello! What I am trying to do is have a 'automated picking list.' In other words, I will have a checklist of item. (I.e. Apple, pear, banana). Each of the items have a specific barcode, 321, 654, and 987 respectively. So, when an item is scanned, I would like it to be automatically 'checked' off the list. Below I put a matlab script with the general idea. I want to implement this logic with the App Designer Toolbox, however I am not able to edit the. Anything with a white background is editable, and a grey background is uneditable. I want to implement the for and if else loops in the .m code to line 49, the value of the checkbox, to change it's toggle instead of print a statement but I cant edit it! any suggestions?
barcode = [321 654 987];
prompt = 'Enter a string of digits to represent a barcode: ';
x = input(prompt);
c = 0;
%For loop will check if scanned item is within list, if so will mark c = 1
for i = 1:length(barcode)
if barcode(i) == x
c = 1;
end
end
%If loop will check item if c = 1
if c == 1
disp('Item Checked!')
else
disp('ERROR: Item Not Required')
end
6 Kommentare
Athrey Ranjith Krishnanunni
am 16 Jan. 2021
You have to use the actual checkbox names for dynamically referencing them as fields of the object app. In your code, you have modified the property checkBoxNames as:
checkBoxNames = {'Apple', 'Pear', 'Banana', 'Orange'}
so the line
app.(checkedBoxName).Value = 1;
evaluates to
app.Apple.Value = 1;
and app.Apple doesn't exist, which is what the error means.
To fix it, use the full names of the checkboxes (you can see them from Component Browser on the right pane), like I had mentioned in my original code:
checkBoxNames = {'AppleCheckBox','PearCheckBox','BananaCheckBox','OrangeCheckBox'};
Akzeptierte Antwort
Athrey Ranjith Krishnanunni
am 16 Jan. 2021
So basically, the trick here is to find which checkbox's value should be changed when the scanned item matches its corresponding barcode.
OP has said that the scanned item is represented by a number x inside a callback function tied to the scanning process.
So we first save the barcodes of all items in the store as a property of the app, along with the actual full names of the checkboxes they each represent.
properties (Access = private)
barcode = [321 654 987];
checkBoxNames = {'AppleCheckBox','PearCheckBox','BananaCheckBox'};
% in the same order as that of barcode
end
It's important to use the full names of the checkboxes because we'll later use it to refer to the actual checkboxes themselves.
Now, inside the callback function, after x is assigned the barcode of the scanned item, we add the following code:
% see if any entries in barcode are also there in x
isItemChecked = ismember(app.barcode,x);
if ~any(isItemChecked)
disp('ERROR: Item Not Required') % use UIALERT instead to show it on top of your app
return
end
% find names of boxes that are checked
checkedBoxes = app.checkBoxNames(isItemChecked);
% change the value of corresponding checkboxes to 1
for itemNo = 1:numel(checkedBoxes)
checkedBoxName = checkedBoxes{itemNo};
app.(checkedBoxName).Value = 1; % read about dynamic field referencing
end
disp('Item Checked!') % UIALERT like earlier
app.(checkedBoxName) evaluates to app.AppleCheckBox, app.PearCheckBox, etc. depending on context.
0 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Environment and Settings finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!