ramCC Posted June 20, 2004 Posted June 20, 2004 Anybody with a clue on why this code (man c++): String *myTime = DateTime::Now.ToString(L"dd/MM/yyyy HH:mm:ss", DateTimeFormatInfo::InvariantInfo); sometimes facilitate 'myTime' with the correct time , and sometimes just stayed <undefined> (NULL) . Thanks. Quote
*Experts* Nerseus Posted June 21, 2004 *Experts* Posted June 21, 2004 I've noticed that .NET 2003 seems a lot "smarter" when you're debugging. If you define a simple int and set it to 0 and run it (never using it again in a function), the compiler will often show "undefined value" even though you clearly set it to 0. The same goes for objects that are defined but never "used". The compiler, I think, is trimming out that code since it detects it never being used. In the cases where it says "undefined value" are you using the variable farther down, or just testing the initialization? Try creating a class level field and setting that if you just need to test. If that's not it, let me know and I'll see if I can narrow it down. -Nerseus Quote "I want to stand as close to the edge as I can without going over. Out on the edge you see all the kinds of things you can't see from the center." - Kurt Vonnegut
ramCC Posted June 21, 2004 Author Posted June 21, 2004 Hey Nerseus, thanks for your reply ! I am using the object further down, so I guess its not a compiler issue. the relevant function is: void txMgr::AddLogEntry(String *i_logEntry, Char i_warnning[], Char i_error[]) { String *line = DateTime::Now.ToString(L"dd/MM/yyyy HH:mm:ss", DateTimeFormatInfo::InvariantInfo); line = line->Concat(i_logEntry); if(line->Length > 255) line = line->Substring(0,255); m_logFile->WriteLine(line); m_logFile->Flush(); } The strange thing is that on my log file (m_logFile) on some cases I do see the date prefix and on other cases I dont (only the i_logEntry). On debugging I see that nothing comes back from DateTime::Now.ToString() even though I do see the Now object (when doing "DateTime now = DateTime::Now") . Maybe there is a problem with the ToString ? I have no idea ... Quote
*Experts* Nerseus Posted June 21, 2004 *Experts* Posted June 21, 2004 Offhand, I can't think of any reason why the ToString would ever cause a problem. Have you tried using Debug.Assert right after the line that instantiates *line, to see if it's empty string or null? -ner Quote "I want to stand as close to the edge as I can without going over. Out on the edge you see all the kinds of things you can't see from the center." - Kurt Vonnegut
ramCC Posted June 22, 2004 Author Posted June 22, 2004 Thanks Nerseus ! I found the problem with this code, and it had nothing to do with DateTime object or the ToString function. The problem was the use of Concat ... I used: line = line->Concat(i_logEntry); instead of: line = String::Concat(line, i_logEntry); My common sense told me it will yield the same result, but I guess my common sense has no place in this world ... Thanks a lot anyways Ram. Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.