MATLAB: Object handle is being defined without me telling it and I don’t know why.

gui edit text function value

Hi, I've been creating a GUI and I've noticed something odd that I am unfamiliar with. I have a edit text function that is being given an arbitrary value without me defining.
In the creation of the function I define rise to be 0:
function rise_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
rise = 0;
handles.rise = rise;
guidata(hObject, handles);
I have a push button that is supposed to take that value and check if it was left blank (rise = 0) or not. Instead when I call the handle in the check function, it is given a value of 203.0048. It should still be 0. Why? Here's the beginning of the check function.
function checkout = errorcheck(handles)
rise = handles.rise
My output for rise is always the 203.0048 value. I output the value of rise throughout my script and the only place it changes is in the checkout function I made. I have checked the handle properties in debug mode, and I can't find any explanation. I am calling all other variables in my GUI the same way and without this problem. Anyone have insight? Thanks.

Best Answer

If the value in the edit field is 203.0048, that is the String property, and in ANY callback (pushbutton, edit field, slider, whatever), you can access that edit field as a string or number by doing this
editFieldContents = handles.rise.String;
% Now convert that string into a number (optionally, if you want to).
handles.riseValue = str2double(editFieldContents); % DO NOT use handles.rise.
Do not use handles.rise or you will blow away the way that your GUI can communicate with that uicontrol. Call it something else - anything but not the "tag" name of any of the controls.
To set the contents of the edit field, you can (again, from ANY callback at all) do:
% Convert number to a string and send it to the edit field.
handles.rise.String = num2str(123.4567);