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

I am so lost. 1

Status
Not open for further replies.

Confusedguy

Programmer
Aug 31, 2006
3
US
Alright... I'm looking absolutely everywhere in MSDN to try and figure this out... but to no avail. I'm trying to get the current time in my Windows Forms Application. All the code I find, doesn't work. I tried this snippet I found in MSDN:
char timebuf[128];
_strtime_s(timebuf);

NOW:
how do I display this in a label on my form?!?! i tried
this->lblShutdownInit->Text = timebuf;
but i get an error:
Form1.h(249) : error C2664 : 'void System:: Windows::Forms::Control::Text::set(System::String ^)' : cannot convert parameter 1 from 'car [128]' to 'System::String ^'
No user-defined-conversion operator available, or Cannot convert an unmanaged type to a managed type



so it can't convert from char to System::String. So I tried changing Char to System::String, and i still get errors. I'm learning C++, but I have no idea if Visual C++ has different ways of doing things or what... but shouldn't that work??
 
try using DateTime object.

------------------
When you do it, do it right.
 
You need your original declaration to be char[128] to use with _strtime_s.

Then you need another variable of type System::String. I suspect you can pass your character array into the constructor for the new String.

Then set your item text to your new String.
 
Ok, so I figured something out here. Looked up DateTime and found out this little snippet, which works for grabbing the time:
//Get current time ct = DateTime::Now;

Now, what I want to do is compare that to a DateTimePicker object's value (what the user will set the time to shutdown to be). Now, I can't just use a simple if (ct == settime) because it just doesn't work that way.
I need to use the strtok function to separate each bit of info (month, year, day, hour, minute) so I can then do something like if (ct[1] == settime[1]) to see if they're the same. Problem is, strtok doesn't take a DateTime variable. I need to convert it to a char variable. How the hell do I take the value of that DateTime variable and copy it into a char variable so I can use this strtok function??! Or am I looking at this all the wrong way?
 
Woo! I figured it out, without having to do any crazy type conversions, either.
I used
int TimeCompare = DateTime::Compare(ct, st);
if (TimeCompare >= 0) {
//Throw error
}

Anyone have any idea how to shut the system down in XP now?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top