Static Text update according to GUI List box callback

2 views (last 30 days)
I am trying to update my static text with tag text105 on my gui according to the value selected from the list box. The code I have developed is below, but it failed to display the value. Kindly spot the error.
function listbox1_Callback(hObject, eventdata, handles)
a=get(handles.listbox1,'value')
if (a==Natural-Gas)
Cv=12500;
set(handles.text105,'string',Cv)
drawnow;
elseif (a==Propane-Butane)
Cv=11950;
set(handles.text105,'string',Cv)
drawnow;
elseif (a==Fuel-Oil)
Cv=9520;
set(handles.text105,'string',Cv)
drawnow;
elseif (a==Diesel)
Cv=1000;
set(handles.text105,'string',Cv)
drawnow;
elseif (a==Brown-Coal)
Cv=3500;
set(handles.text105,'string',Cv)
drawnow;
elseif (a==Woods)
Cv=2500;
set(handles.text105,'string',Cv)
drawnow;
elseif (a==Electricity)
Cv=860;
set(handles.text105,'string',Cv)
drawnow;
end

Answers (1)

BhaTTa
BhaTTa on 12 Jun 2025
Hey @Muhammad Salman Arif, You’re comparing the index (a) to literal strings like Natural-Gas, which is incorrect. The Value property returns an integer (the selection index), not the string itself. Also, you're using unquoted identifiers like Natural-Gas, which is incorrect

Categories

Find more on Loops and Conditional Statements in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!