Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Check for NULL value in CEDIT

264 views
Skip to first unread message

IMS

unread,
Mar 9, 1998, 3:00:00 AM3/9/98
to

Hi,

I want to know how to check empty string in a edit box.

Thanks

Katy Mulvey

unread,
Mar 10, 1998, 3:00:00 AM3/10/98
to

In <6durmt$dp4$1...@imsp009a.netvigator.com>, IMS

<mf...@netvigator.com> wrote:
> I want to know how to check empty string in a edit box.

Since you're posting to an MFC group, I assume you want an
MFC solution -- map a CString to the edit box, call
UpdateData(true) in the appropriate place (to transfer the
data from the edit control to your string variable), and
then check m_strYourEdit.IsEmpty().

Katy [MVP/VC++]

George Mihaescu

unread,
Mar 11, 1998, 3:00:00 AM3/11/98
to

This is the "no-brainer" approach, but for less stress on the
memory rather than map a member CString to the control use a
local variable. Besides, the approach proposed above would not
work unless in a dialog. A better solution:

CEdit* p_ed = .... //get it from somewhere, if in dialog do
//(CEdit*) GetDlgItem (ID_MYEDIT);

char text [2];
p_ed -> GetWindowText (text, 1);
if (strlen (text) > 0)
{
//it's not empty
}
else
{
//it's empty
}

Regards,
George

Jan Arvidsson

unread,
Mar 12, 1998, 3:00:00 AM3/12/98
to

On Wed, 11 Mar 1998 14:25:40 -0500, George Mihaescu
<gabi...@utoronto.ca> wrote:

>This is the "no-brainer" approach, but for less stress on the
>memory rather than map a member CString to the control use a
>local variable. Besides, the approach proposed above would not
>work unless in a dialog. A better solution:
>
>CEdit* p_ed = .... //get it from somewhere, if in dialog do
> //(CEdit*) GetDlgItem (ID_MYEDIT);
>
>char text [2];
>p_ed -> GetWindowText (text, 1);
>if (strlen (text) > 0)
>{
> //it's not empty
>}
>else
>{
> //it's empty
>}
>
>Regards,
>George

Will the 'text' string variable be initialized, so you can test it
with strlen(), if GetWindowText for some reason returns 0?

Regards,
Janne

ClaudeV

unread,
Mar 23, 1998, 3:00:00 AM3/23/98
to

Here is a lazier solution:

CEdit* p_ed = .... //get it from somewhere, if in dialog do
//(CEdit*) GetDlgItem (ID_MYEDIT);

if (p_ed -> GetWindowTextLength () > 0)


{
//it's not empty
}
else
{
//it's empty
}

or the laziest one
SendDlgItemMessage( ID_MYEDIT, WM_GETTEXTLENGTH )
will obviously return the text length

Have fun Katy
Claude

George Mihaescu wrote in message <3506E5...@utoronto.ca>...


>Katy Mulvey wrote:
>>
>> In <6durmt$dp4$1...@imsp009a.netvigator.com>, IMS
>> <mf...@netvigator.com> wrote:
>> > I want to know how to check empty string in a edit box.
>>
>> Since you're posting to an MFC group, I assume you want an
>> MFC solution -- map a CString to the edit box, call
>> UpdateData(true) in the appropriate place (to transfer the
>> data from the edit control to your string variable), and
>> then check m_strYourEdit.IsEmpty().
>>
>> Katy [MVP/VC++]
>

0 new messages