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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

CString text being hidden or truncated by a special character?

Status
Not open for further replies.

Vachaun22

Programmer
Oct 7, 2003
171
US
I am accessing a MS Access database to get some information to show as a tooltip over a tree control.

There are 2 fields in particular that are causing some interesting effects on a CString variable. The field types are (in Access) Currency, and Memo. This issue only appears with these 2 fields.

Here is the code that has the issue:

Code:
CString strTemp;

// Plan Name
sTipText += _T(" Plan: ") + value;

// Minutes
cRS.GetFieldValue( (short)2, key );
strTemp.Format( _T("%d"), key.m_iVal );
key.Clear();
sTipText += _T("\r\n Minutes: ") + strTemp;
strTemp = _T("");

// Price
cRS.GetFieldValue( (short)3, strTemp );
strTemp.Replace(_T("00"), _T(""));
sTipText += _T("\r\n Price: ") + strTemp;
strTemp = _T("");

// Description
cRS.GetFieldValue( (short)4, strTemp );
strTemp.Replace(_T("&"), _T("and"));
sTipText += _T("\r\n Description: ") + strTemp;
strTemp = _T("");

data->SetToolTipString( sTipText );
CString sLength;
sLength.Format(_T("%d"), sTipText.GetLength() );
AfxMessageBox( sLength );
AfxMessageBox( sTipText );

An interesting thing happens when stepping through the code. When setting the description, the line:

sTipText += _T("\r\n Description: ") + strTemp;

Does not appear to do anything. On all other lines where sTipText gets concatenated with another string, it turns to red to show it's the value being worked with, however it doesn't on that line. It's like that line is being ignored.

However, if I just add some generic text over those 4 lines, instead of the data from the database, there is no issue.

Are there non-printable characters that would prevent concatenation to a CString variable that might be in the data and I can't tell?

Anyone have any suggestions?
 
I figured out the issue.

These fields were tacking on null termination characters at the end of the string.

I simply got a substring of the original string that didn't include those characters, and all worked smoothly.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top