From: Jon Mock on
I'm looking to build a GUI where you input numbers into text boxes then, the main program reads these values and stores them to a text file.

Here's what I've added to the main program

% Input Callback
input = str2double(get(hObject, 'String'));

handles.user_input = input
guidata(hObject, handles)

% Pushbutton Callback
fid1 = fopen('VATS_INPUT.txt', 'wt');

fprintf(fid1, '%-21.0f', str2double(get(handles.user_input, 'String')));
fprintf(fid1, 'User Input: User Input. \n');

fclose('all');

guidata(hObject, handles)

I'm continuing to get errors and was wondering if anyone had any ideas about the best way to do this.

Errors:
??? Error using ==> get
Invalid handle object.

Error in ==> Practice>write_Callback at 117
fprintf(fid1, '%-21.0f', str2double(get(handles.user_input, 'String')));

Error in ==> gui_mainfcn at 96
feval(varargin{:});

Error in ==> Practice at 42
gui_mainfcn(gui_State, varargin{:});

Error in ==> @(hObject,eventdata)Practice('write_Callback',hObject,eventdata,guidata(hObject))


??? Error while evaluating uicontrol Callback

Thanks -jm
From: neil on
"Jon Mock" <jon.mock(a)gmail.com> wrote in message <i2acas$9uk$1(a)fred.mathworks.com>...
> I'm looking to build a GUI where you input numbers into text boxes then, the main program reads these values and stores them to a text file.
>
> Here's what I've added to the main program
>
> % Input Callback
> input = str2double(get(hObject, 'String'));
>
> handles.user_input = input
> guidata(hObject, handles)
>
> % Pushbutton Callback
> fid1 = fopen('VATS_INPUT.txt', 'wt');
>
> fprintf(fid1, '%-21.0f', str2double(get(handles.user_input, 'String')));
> fprintf(fid1, 'User Input: User Input. \n');
>
> fclose('all');
>
> guidata(hObject, handles)
>
> I'm continuing to get errors and was wondering if anyone had any ideas about the best way to do this.
>
> Errors:
> ??? Error using ==> get
> Invalid handle object.
>
> Error in ==> Practice>write_Callback at 117
> fprintf(fid1, '%-21.0f', str2double(get(handles.user_input, 'String')));
>
> Error in ==> gui_mainfcn at 96
> feval(varargin{:});
>
> Error in ==> Practice at 42
> gui_mainfcn(gui_State, varargin{:});
>
> Error in ==> @(hObject,eventdata)Practice('write_Callback',hObject,eventdata,guidata(hObject))
>
>
> ??? Error while evaluating uicontrol Callback
>
> Thanks -jm

Hi Jm

You code is a little difficult to follow since it is just an extract. Possibly add your function headers too and where you create the callbacks (if not in GUIDE).
I would have to say you are not using GUIDATA correctly.

When you do:
> guidata(hObject, handles)
Since hObject is the handle to the input box object you are setting handles to the GUI data for the text box object.
Then in the button callback you are expecting the handles structure (which is now that of the figure) to be the on of the edit button.

Also since you mentioned you have multiple text boxes it may be difficult to know which data comes from where.

Try use getappdata and setappdata instead of using guidata, to set and read the input values.

eg
%text box callback
appdata.box1Value = str2double(get(hObject, 'String'))
setappdata(handle.figureHandle,'appdata',appdata);

%button callback
appdata = getappdata(handle.figureHandle,'appdata');

OR

Just read the value from the text box in the button callback

fprintf(fid1, '%-21.0f', str2double(get(handles.textBoxHandle, 'String')));

You will have to know the handle name of text box and figure. But it should work.

Post if you are still struggling
Neil