Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

GetLength() not working?

Status
Not open for further replies.

minifiredragon

Programmer
Jun 29, 2003
68
US
When I do the GetLength() I get an error when I check the number. No matter what length I make it, it always is wrong.

Here is what I have, and quite frankly I don't see any error in the code.

void CInsertDlg::OnOK()
{

// TODO: Add your specialized code here and/or call the base class
//ESM Code
//Check Input for proper number
CheckNum(m_sCardNum);

CDialog::OnOK();
}



void CInsertDlg::CheckNum(CString number)
{
int length;
ten = 1;
length = number.GetLength();
if ( length < 10 )
AfxMessageBox(&quot;Error, incorrect number&quot;, MB_ICONSTOP | MB_OK);
}

 
>Here is what I have, and quite frankly I don't see any error in the code

Perhaps the m_sCardNum never gets a value?

(ignoring the ten = 1; thingie)



/Per
Nerdy signatures are as lame as the inconsistent stardates of STTNG.
 
The ten = 1; isn't suppose to be there, and the m_sCardNum does get a value as I have checked it for one. And if it didn't, setting my code to:

if ( length < 0 )
AfxMessageBox(&quot;Error, incorrect number&quot;, MB_ICONSTOP | MB_OK);

would not through up the error message, no?

I did check it, and that works... but.. but...

<back to the drawing board>
 
What do you expect m_sCardNum to be? A number with more than 10 digits?

You do realize that GetLength returns the length of the string?
Ie.
CString s(&quot;1234567890&quot;); // s.GetLength() == 10
CString s(&quot;abcdef&quot;); // s.GetLength() == 5
CString s(&quot;3&quot;); // s.GetLength() == 1
CString s(&quot;3.14&quot;); // s.GetLength() == 4


/Per
Nerdy signatures are as lame as the inconsistent stardates of STTNG.
 
Note to self:
&quot;abcdef&quot; is 6 chars not 5, you silly fnurt.


/Per
Nerdy signatures are as lame as the inconsistent stardates of STTNG.
 
That wasn't the problem. I assumed when one clicks the OK button that the data is updated 1st. Which I found out isn't the case. It seems UpdateData is passed after the coding in the OnOK(). So I added the UpdateData(TRUE); and walla! It worked. :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top