Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
Home » Community » Newbie corner » [SOLVED] Empty values to the "EditInt" widget and the "int" basic type
[SOLVED] Empty values to the "EditInt" widget and the "int" basic type [message #52589] Thu, 24 October 2019 22:30 Go to next message
xrysf03 is currently offline  xrysf03
Messages: 43
Registered: November 2018
Location: CZ
Member
Hello everybody,

another stupid noob question.

In a simple GUI application, I have two EditInt widgets, called From and To.
I understand that the EditInt is a subclass of an "Editbox" that can only accept integers.
The EditInt widget is willing to remain empty - in which case I would understand that it contains no valid integer value. But, to the best of my knowledge, a traditional "int" type does not have a NaN value. So I was wondering if there's a way for me to test, if the EditInt widget contains a valid integer value, or is empty. I haven't found any such member function or flag to the EditInt object...

I've tried assigning the value of the EditInt widget to a basic "int" variable, declared locally in a function. And then I passed that int variable into a String, and I printed that string.

What I find shocking: the empty value from the editbox apparently made it into the printed string as an empty string, i.e. "".

This is my code almost verbatim:

String tmp_str;
int _from, _to;
_from = Edit_from;
_to = Edit_to;
tmp_str << "From: " << _from << " To: " << _to;
log_this(tmp_str);

...and in the log I get:
"From: To: "
If I type in some numbers, I get those numbers. E.g.:
"From: 100 To: 200"

Is the "int" type overloaded with some higher-level class?
Is there a way for me to test the EditInt or the basic "int" type for an empty value?
I need this for basic user input sanitization.

Frank Rysanek

[Updated on: Fri, 25 October 2019 11:00]

Report message to a moderator

Re: Empty values to the "EditInt" widget and the "int" basic type [message #52591 is a reply to message #52589] Fri, 25 October 2019 08:35 Go to previous messageGo to next message
koldo is currently offline  koldo
Messages: 3355
Registered: August 2008
Senior Veteran
Dear Frank

It is simple. U++ uses a special value for all usual types, U++ classes and some most used C++, that is Null.

If you have an EditInt and you want to know if it is empty or not, just do:
if (IsNull(myEdit))
	Exclamation("Please enter a number");

IsNull() function is the way to test if a variable is Null.
If you look in U++ sources and examples, you will find tons of IsNull() Smile


Best regards
Iñaki
Re: Empty values to the "EditInt" widget and the "int" basic type [message #52597 is a reply to message #52591] Fri, 25 October 2019 10:58 Go to previous messageGo to next message
xrysf03 is currently offline  xrysf03
Messages: 43
Registered: November 2018
Location: CZ
Member
@Koldo thanks for your endless patience Smile and for all your help.

Yes I've been fumbling for IsValid or IsNull in the autocompletion suggestions and in the built-in help, as a member method - but it never occured to me to look for it as a stand-alone function (I really wouldn't know how, it doesn't jump at me via autocompletion). Trawl the examples, that was the one thing I gave up, in favour of asking yet another silly question.

I don't mean to complain, there are always sweet secrets when learning a new environment, and I sure do recall the old days when we were not spoilt by omnipresent hints and instant help Smile And it's a modern marvel of the world to have a place to ask, and get a friendly answer overnight.

Once again you have patiently answered several facettes of my question. Thank you Smile

Frank
Re: Empty values to the "EditInt" widget and the "int" basic type [message #52601 is a reply to message #52597] Fri, 25 October 2019 12:26 Go to previous message
koldo is currently offline  koldo
Messages: 3355
Registered: August 2008
Senior Veteran
You're welcome.

Never hesitate to ask, always trying to be simple and clear in your questions.

There are no silly questions, but sometimes stupid answers. Here, we try not to be stupid Smile


Best regards
Iñaki
Previous Topic: [solved] U++ TheIDE integrated debugging tutorial ?
Next Topic: [solved]An U++ equivalent of bzero ? (if not a sin)
Goto Forum:
  


Current Time: Fri Mar 29 00:51:32 CET 2024

Total time taken to generate the page: 0.01153 seconds