"albert carero" wrote in message <mh6bbq$66h$1@newscl01ah.mathworks.com>...
> In GUI there are
>
> 1 One Checkbox
> 2. One Pushbutton
>
> i want to make when i check the checkbox , it will load data.txt for pushbutton so the pushbutton can use that data to execute other command
>
> i try something like in this thread http://www.mathworks.com/matlabcentral/newsreader/view_thread/137440. but cant work
>
> for some reason either i checked my checkbox or not , my PushButton Still can load my Data.txt
>
> i do
>
> % --- Executes on button press in checkbox1.
> function checkbox1_Callback(hObject, eventdata, handles)
> set(handles.checkbox1,'Value',1)
> global cb
> if get(handles.checkbox1,'Value')==1
> cb=1 %%so that you know which checkbox1 was checked
> end
> ( For my CheckBox)
>
> % --- Executes on button press in pushbutton2.
> function pushbutton2_Callback(hObject, eventdata, handles)
> global cb
> if(get(handles.pushbutton2, 'Value'))==1
> if cb == 1
> load data.txt;
> else
> load dat.png;
> end
> end
> (For My PushButton)
>
> And
>
> % --- Executes just before JST is made visible.
> function JST_OpeningFcn(hObject, eventdata, handles, varargin)
> set(handles.checkbox1,'Value',0)
> (for initialization )
>
> use listbox, toggle button or other way to use instead of Checkbox also welcome
> (my purpose is to load multiple .txt for my pushbutton from multiple choice)
>
> thank you very much for everyone who read and comment in this thread :)
I'm not sure why you use that global cb variable. (I realize that you copied it from the thread that you linked, but I don't understand why they used it there, either.)
You can always determine whether a checkbox is checked simply by using get(handles.checkbox1,'Value'), for example:
if get(handles.checkbox1,'Value')
...
end
More importantly, I don't know why you have the line,
if(get(handles.pushbutton2, 'Value'))==1
It doesn't look like you are ever changing the value of pushbutton2, so testing its value won't tell you anything. The value does not change when the pushbutton is pushed - the callback function is simply called - that's how you know it's been pushed.
I think you just need this:
% --- Executes on button press in pushbutton2.
function pushbutton2_Callback(hObject, eventdata, handles)
if get(handles.checkbox1,'Value')
load data.txt;
else
load dat.png;
end
> In GUI there are
>
> 1 One Checkbox
> 2. One Pushbutton
>
> i want to make when i check the checkbox , it will load data.txt for pushbutton so the pushbutton can use that data to execute other command
>
> i try something like in this thread http://www.mathworks.com/matlabcentral/newsreader/view_thread/137440. but cant work
>
> for some reason either i checked my checkbox or not , my PushButton Still can load my Data.txt
>
> i do
>
> % --- Executes on button press in checkbox1.
> function checkbox1_Callback(hObject, eventdata, handles)
> set(handles.checkbox1,'Value',1)
> global cb
> if get(handles.checkbox1,'Value')==1
> cb=1 %%so that you know which checkbox1 was checked
> end
> ( For my CheckBox)
>
> % --- Executes on button press in pushbutton2.
> function pushbutton2_Callback(hObject, eventdata, handles)
> global cb
> if(get(handles.pushbutton2, 'Value'))==1
> if cb == 1
> load data.txt;
> else
> load dat.png;
> end
> end
> (For My PushButton)
>
> And
>
> % --- Executes just before JST is made visible.
> function JST_OpeningFcn(hObject, eventdata, handles, varargin)
> set(handles.checkbox1,'Value',0)
> (for initialization )
>
> use listbox, toggle button or other way to use instead of Checkbox also welcome
> (my purpose is to load multiple .txt for my pushbutton from multiple choice)
>
> thank you very much for everyone who read and comment in this thread :)
I'm not sure why you use that global cb variable. (I realize that you copied it from the thread that you linked, but I don't understand why they used it there, either.)
You can always determine whether a checkbox is checked simply by using get(handles.checkbox1,'Value'), for example:
if get(handles.checkbox1,'Value')
...
end
More importantly, I don't know why you have the line,
if(get(handles.pushbutton2, 'Value'))==1
It doesn't look like you are ever changing the value of pushbutton2, so testing its value won't tell you anything. The value does not change when the pushbutton is pushed - the callback function is simply called - that's how you know it's been pushed.
I think you just need this:
% --- Executes on button press in pushbutton2.
function pushbutton2_Callback(hObject, eventdata, handles)
if get(handles.checkbox1,'Value')
load data.txt;
else
load dat.png;
end