From: Richard Conforti on
Walter Roberson <roberson(a)hushmail.com> wrote in message <hscnn8$oie$2(a)canopus.cc.umanitoba.ca>...
> Richard Conforti wrote:
> > Walter Roberson <roberson(a)hushmail.com> wrote in message
> > <hs9nq8$4l$1(a)canopus.cc.umanitoba.ca>...
> >> Richard Conforti wrote:
>
> >> > Here is my code.
> >> > > function e_checkbox_Callback(hObject, eventdata, handles)
> >> > checkboxStatus = get(handles.e_checkbox,'Value');
> >> > if checkboxStatus==1
> >> > e=10;
> >> > elseif checkboxStatus == 0
> >> > e=1; end
>
> >> You do not indicate what error you are receiving.
>
> >> I do note, though, that you do not appear to do anything with e after
> >> you set that variable.
>
> > Sorry about that, the error I am recieving is Undefined variable e.
> > Further down the GUI I am attempting to use the value from the check box
> > to plug into a formula.
>
> Well, like I said before "you do not appear to do anything with e after you
> set that variable". When you get to the end of e_checkbox_Callback, the value
> of e is going to disappear unless you somehow save it somewhere, perhaps using
> the guidata() function.

Thanks, I have that problem solved, but now I am getting a different error message.

If I try to click on a different checkbox I get the error;
??? Attempt to reference field of non-structure array.

My code is as follows
% --- Executes on button press in x_checkbox.
function x_checkbox_Callback(hObject, eventdata, handles)
checkboxStatusx = get(handles.x_checkbox,'Value')
if checkboxStatusx==1
%if box is checked, text is set to bold
x=15
elseif checkboxStatusx == 0
x=1
end
guidata(handles.x_checkbox, x)



% Hint: get(hObject,'Value') returns toggle state of x_checkbox


% --- Executes on button press in l_checkbox2.
function l_checkbox2_Callback(hObject, eventdata, handles)
checkboxStatusl = get(handles.l_checkbox2,'Value')
if checkboxStatusl==1
%if box is checked, text is set to bold
l=5
elseif checkboxStatusl == 0
l=1
end
guidata(handles.l_checkbox2, l)

% hObject handle to l_checkbox2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)

% Hint: get(hObject,'Value') returns toggle state of l_checkbox2


% --- Executes on button press in e_checkbox1.
function e_checkbox1_Callback(hObject, eventdata, handles)
checkboxStatuse = get(handles.e_checkbox1,'Value')
if checkboxStatuse==1
e=10
elseif checkboxStatuse == 0
e=1
end
guidata(handles.e_checkbox1, e)

% hObject handle to e_checkbox1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)

% Hint: get(hObject,'Value') returns toggle state of e_checkbox1


% --- Executes on button press in t_checkbox.
function t_checkbox_Callback(hObject, eventdata, handles)
checkboxStatust = get(handles.t_checkbox3,'Value')
if (checkboxStatust==1)
%if box is checked, text is set to bold
t=4
elseif checkboxStatust == 0
t=1
end
guidata(handles.t_checkbox3, t)
From: Walter Roberson on
Richard Conforti wrote:

> Thanks, I have that problem solved, but now I am getting a different
> error message.
>
> If I try to click on a different checkbox I get the error;
> ??? Attempt to reference field of non-structure array.
>
> My code is as follows
> % --- Executes on button press in x_checkbox.
> function x_checkbox_Callback(hObject, eventdata, handles)
> checkboxStatusx = get(handles.x_checkbox,'Value')
> if checkboxStatusx==1
> %if box is checked, text is set to bold
> x=15
> elseif checkboxStatusx == 0
> x=1 end
> guidata(handles.x_checkbox, x)

When you are checking the value of a checkbox within the callback for
that checkbox, then instead of referencing handles.x_checkbox or
whatever, you are better off referencing hObject

function x_checkbox_Callback(hObject, eventdata, handles)
checboxStatus = get(hObject, 'Value');
[etc]