Filter löschen
Filter löschen

Saving Items Different listbox in a text file (App designer)

1 Ansicht (letzte 30 Tage)
Siria Fumagalli
Siria Fumagalli am 15 Okt. 2019
Beantwortet: Abhilash Padma am 31 Dez. 2019
It's the first time i'm using app designer i'm trying to save the items of different Listbox in one file.txt
I report the code of the list box.
The structure of the file should be "
Firstlist:
Item=Itemdata
Item1=ItemData1
Secondlist:
Itemsecondlist=Itemdatasecondlist
Thirdlist:
Itemthitdlist=Itemdatathirdlist
.."
function AddButtonPushed(app, event)
%when the Addbutton is pushed the listbox is filled with the
%string written in the editfield and a code is associated in
%the ItemsDAta
app.ComandiListBox.Items = [string(app.ComandiListBox.Items),string(app.aggiungiEditField.Value)];
app.ComandiListBox.ItemsData = [app.ComandiListBox.ItemsData, app.codiceEditField.Value];
end
%I've tried something like that for the first listbox but isn't working
function SaveButtonPushed(app, event)
C=num2cell(app.ComandiListBox.ItemsData);
C2=[app.ComandiListBox.Items; C];
fileID = fopen('prova1.txt','w');
formatSpec = '%s=%d\n';
[nrows,ncols] = size(C2);
for row = 1:nrows
fprintf(fileID,formatSpec,C2{row,:});
end
fclose(fileID);
end

Antworten (1)

Abhilash Padma
Abhilash Padma am 31 Dez. 2019
If you want to save the items of a list box when selected, you can use the ‘’ValueChangedFcn” callback of list box to save the items in a text file. See the code below where I have used a list box in my app with different values and saving the value when selected:
function cityListBoxValueChanged(app, event)
value = app.cityListBox.Value;
fileID = fopen('example2.txt','w');
fprintf(fileID,'%s = %s','val1',value);
end

Kategorien

Mehr zu Migrate GUIDE Apps 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!

Translated by