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 Chriss Miller 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
Joined
Aug 31, 2006
Messages
3
Location
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?
 
You probably don't want to compare them for == anyhow, since you aren't guarenteed to hit the time "on the nose". You have to use >=.

I just looked up DateTimePicker. The getDate member returns a Date. So you want your current date in a Date as well, so your >= should work.

 
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?
 
Try that:

System.Diagnostics.Process.Start("Shutdown", "/s")
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top