Using an if clouse, and based on a generated code ie User ID displayed in a textbox, how can i link the ID to a user name of choice by displaying the name in a txt box

1 次查看(过去 30 天)
My GUI has two text boxes, User ID and User name. The user ID is automatically generated by an OCR engine i created. I want to extract the user id and use the IF clause to display a corresponding User name on the user name text box e.g if the user id generated is UAK008 then the user name is 'somebody' of choice upon pressing a push button.

采纳的回答

PT
PT 2013-3-27
Let's assume the following: The tag for the pushbutton is "update". The tag for the User ID editbox is "userid". The tag for the User name text box is "username".
Then in the callback function for update:
function update_Callback (hObject, eventdata, handles)
uid = get(handles.userid, 'String');
lookupTable = {
'UAK001' 'Joe'
'UAK002' 'Joel'
'UAK003' 'John'
'UAK004' 'Bob'
};
uname = '';
for i = 1:size(lookupTable,1)
if strcmp(lookupTable(i,1), uid)
uname = lookupTable(i,2);
break;
end
end
if ~isempty(uname)
set(handles.username, 'String', uname);
else
set(handles.username, 'String', 'Username not found!');
end

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Startup and Shutdown 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by