I want to know how to check empty string in a edit box.
Thanks
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++]
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
>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
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++]
>