tags:

views:

140

answers:

3

Hello i am developing an MFC application in vc++ 6.0.I created one int variable(m_iEdit1) to the EditBox1 and one CString variable(m_strEdit2) to the EditBox2. I wanted to give the condition that two editbox must not be empty.

if(m_iEdit1==" ")
return;

if(m_strEdit2==" ")
return;

But the first condition will not work here i will get error error C2446: '==' : no conversion from 'char *' to 'int'

please tell me how to check an int Variable of EditBox is Empty or not.

A: 

You'll have to check the actual EditBox variable (did you call it EditBox1?) to see if the value is empty.

You should also consider other checks as well to ensure no one is trying to assign non numerical values to your integer value.

Alan
yes it is actual EditBox1 Variable.How to see the value is empty can u give the example. Thanks in advance
A: 

You can use the GetLine method to get the string from the edit control. Then you can use IsEmpty (assuming you passed a CString) to check whether it is empty.

Naveen
how to convert string to int
because i want intger values not CString
First get the value to a CString. Then you can use functions like _ttoi to convert it to integer.
Naveen
Thank You i Got
+3  A: 

You have to use UpdateData() method.
The m_ variables will not get the data from the controls unless you say it.

UpdateData(TRUE) // the m_ variables will be updated from the controls
UpdateData(FALSE) // the controls will be updated from m_ variables

You want m_iEdit1 to be integer but since you need to check if the EditBox1 is empty change m_iEdit1 to CString. Then you can use

atoi(m_iEdit1)

to get the integer value.

Now that both m_iEdit1 and m_strEdit2 are CStrings you can use the code

if ( m_iEdit1.IsEmpty() ) return;
if ( m_strEdit2.IsEmpty() ) return;
Nick D
Thank You i Got the Result