MATLAB Answers

How do i set a range for the number type in edit text box GUI?

21 ビュー (過去 30 日間)
badrul hisham
badrul hisham 2016 年 5 月 4 日
コメント済み: badrul hisham 2016 年 5 月 8 日
hello everyone.
can someone please show me how can i set a range for the number type in the text box of a GUI. I have a text box in GUI that i want it to accept only number ranged from 1 to 7. if the user input a number outside of the range, the text box will become empty, and a dialog box tells the user to input only a number ranged from 1 to 7, then the user has to input a different number which satisfies the condition. when the number is within range, the system will accept the number and stores it in a variable. lets call the variable as aa. your help is very much appreciated.

  0 件のコメント

サインインしてコメントする。

回答 (1 件)

CS Researcher
CS Researcher 2016 年 5 月 4 日
編集済み: CS Researcher 2016 年 5 月 4 日
Let us say the handle to the edit box is edit_box. In the callback function of the edit_box you can write this:
value = str2double(get(handles.edit_box,'String');
flag = value >= 1 && value <= 7
if ~flag
set(handles.edit_box,'String','');
warndlg('Value Out of Range! Please Enter Again');
else
msgbox('Got the value, On it!');
end
This is of course just an idea. You should modify the code according to your need.

  1 件のコメント

badrul hisham
badrul hisham 2016 年 5 月 8 日
thank you! this is just what i need.

サインインしてコメントする。

Community Treasure Hunt

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

Start Hunting!

Translated by