|
I want to shorten my array into by the use of enum, I have not used it yet can anyone give me an idea?
Here is the code:
SchedDay[0] = "Every Sunday";
SchedDay[1] = "Every Monday";
SchedDay[2] = "Every Tuesday";
SchedDay[3] = "Every Wednesday";
SchedDay[4] = "Every Thursday";
SchedDay[5] = "Every Friday";
SchedDay[6] = "Every Saturday";
SchedDay[7] = "Monthly";
for(schedcount = 0; schedcount<8; schedcount++)
{
c_cbCombo1.InsertString(schedcount, _T(SchedDay[schedcount].c_str()));
}
SchedTime[0] = "12:00 AM";
SchedTime[1] = "1:00 AM";
SchedTime[2] = "2:00 AM";
SchedTime[3] = "3:00 AM";
SchedTime[4] = "4:00 AM";
SchedTime[5] = "5:00 AM";
SchedTime[6] = "6:00 AM";
SchedTime[7] = "7:00 AM";
SchedTime[8] = "8:00 AM";
SchedTime[9] = "9:00 AM";
SchedTime[10] = "10:00 AM";
SchedTime[11] = "11:00 AM";
SchedTime[12] = "12:00 PM";
SchedTime[13] = "1:00 PM";
SchedTime[14] = "2:00 PM";
SchedTime[15] = "3:00 PM";
SchedTime[16] = "4:00 PM";
SchedTime[17] = "5:00 PM";
SchedTime[18] = "6:00 PM";
SchedTime[19] = "7:00 PM";
SchedTime[20] = "8:00 PM";
SchedTime[21] = "9:00 PM";
SchedTime[22] = "10:00 PM";
SchedTime[23] = "11:00 PM";
for(timecount = 0; timecount<24; timecount++)
{
c_cbCombo2.InsertString(timecount, _T(SchedTime[timecount].c_str()));
}
And also how will I insert it to the combobox?
Thanks,
Jayjay
|
|
|
|
|
|
use enum instead of array
Thanks
|
|
|
|
|
How would that shorten anything??
|
|
|
|
|
|
C++ doesn't allow an enum of strings.
--
=====
Arman
|
|
|
|
|
You will have enum with same size and
and how your array size will be shortened it still has to store those many entries.
Only thning will change is instead of hardcoding the strings everywhere you will use enum.
|
|
|
|
|
how can i do that to begin with?
Thanks
|
|
|
|
|
You have to declre enum for the strings u want to use.
e.g.
enum {EVERY_MONDAY,EVERY_SUNDAY...}
enum {TWELVE_AM..}
then you can even write a function that will return the strings whenever required.
e.g
CString/char* GetDay(int iVal)
{
switch(iVal)
{
case EVERY_MONDAY:
return "EVERY_MONDAY";
}
...
}
inside code where ever you wan to use you can directly use EVERY_MONDAY...
and offciourse you have to give names to enum you will be creting.
I guess you have never used enums. may be you can read some help for regarding enums.
|
|
|
|
|
All you want to do is, display the time in the combo box.
How about using a loop and CString::Format() function in it to format and display it?
And then you can store all the formatted strings in array.
Somethings seem HARD to do, until we know how to do them.
_AnShUmAn_
|
|
|
|
|
I am understanding that you want to achieve this with lesser lines of code. If I am right, then:
monsieur_jj wrote: SchedTime[0] = "12:00 AM";
SchedTime[1] = "1:00 AM";
SchedTime[2] = "2:00 AM";
SchedTime[3] = "3:00 AM";
SchedTime[4] = "4:00 AM";
SchedTime[5] = "5:00 AM";
SchedTime[6] = "6:00 AM";
SchedTime[7] = "7:00 AM";
SchedTime[8] = "8:00 AM";
SchedTime[9] = "9:00 AM";
SchedTime[10] = "10:00 AM";
SchedTime[11] = "11:00 AM";
SchedTime[12] = "12:00 PM";
SchedTime[13] = "1:00 PM";
SchedTime[14] = "2:00 PM";
SchedTime[15] = "3:00 PM";
SchedTime[16] = "4:00 PM";
SchedTime[17] = "5:00 PM";
SchedTime[18] = "6:00 PM";
SchedTime[19] = "7:00 PM";
SchedTime[20] = "8:00 PM";
SchedTime[21] = "9:00 PM";
SchedTime[22] = "10:00 PM";
SchedTime[23] = "11:00 PM";
for(timecount = 0; timecount<24; timecount++)
{
c_cbCombo2.InsertString(timecount, _T(SchedTime[timecount].c_str()));
}
You can use this instead of the above quoted code:
CString szTime;
for(int i=0; i<23; ++i)
{
szTime.Format(_T("%d:00 HRS"), i);
c_cbCombo2.InsertString(i, szTime);
}
where c_cbCombo2 is a control variable to the combo box of your interest. I am denoting time in 24 hrs format.
Nobody can give you wiser advice than yourself. - Cicero
.·´¯`·->Rajesh<-·´¯`·.
Codeproject.com: Visual C++ MVP
|
|
|
|
|
|
Nibu babu thomas wrote: http://blogs.msdn.com/vcblog/archive/2008/04/30/enums-macros-unicode-and-token-pasting.aspx[^]
This is definitely not the best way of doing things. I don't see any good reason to employ such an ugly solution when using C++. My opinion is that such a technique might look 'cool', but it makes the codebase look horrible, adds unnecessary bloat and makes it difficult to maintain the code in the longer run. Macro substitution is an extremely blind technique; it never cares for semantics or scope in the code. Stroustrup's advise in his book was to avoid macros as much as possible, in fact not to use it at all. And the C++ committee suggests the same too. If there might be a situation where Macros are the only efficient way to do something, I haven't encountered one such situation.
Add: [No, I am not down-voting you, but neither am I going to vote you up in this case]
Nobody can give you wiser advice than yourself. - Cicero
.·´¯`·->Rajesh<-·´¯`·.
Codeproject.com: Visual C++ MVP
modified on Thursday, May 29, 2008 6:15 AM
|
|
|
|
|
monsieur_jj wrote: SchedTime[0] = "12:00 AM"; SchedTime[1] = "1:00 AM"; SchedTime[2] = "2:00 AM"; SchedTime[3] = "3:00 AM"; SchedTime[4] = "4:00 AM"; SchedTime[5] = "5:00 AM"; SchedTime[6] = "6:00 AM"; SchedTime[7] = "7:00 AM"; SchedTime[8] = "8:00 AM"; SchedTime[9] = "9:00 AM"; SchedTime[10] = "10:00 AM"; SchedTime[11] = "11:00 AM"; SchedTime[12] = "12:00 PM"; SchedTime[13] = "1:00 PM"; SchedTime[14] = "2:00 PM"; SchedTime[15] = "3:00 PM"; SchedTime[16] = "4:00 PM"; SchedTime[17] = "5:00 PM"; SchedTime[18] = "6:00 PM"; SchedTime[19] = "7:00 PM"; SchedTime[20] = "8:00 PM"; SchedTime[21] = "9:00 PM"; SchedTime[22] = "10:00 PM"; SchedTime[23] = "11:00 PM"; for(timecount = 0; timecount<24; timecount++) { c_cbCombo2.InsertString(timecount, _T(SchedTime[timecount].c_str())); }
You could shorten this a bit by trying something like:
for (timecount = 0; timecount<24; timecount++)
{
CString str;
int nHour = timecount % 12;
if (0 == nHour) nHour = 12;
str.Format(_T("%d:00 %s"), nHour, (nHour >= 12 && nHour <= 23) ? _T("PM") : _T("AM"));
c_cbCombo2.InsertString(timecount, str);
}
"Love people and use things, not love things and use people." - Unknown
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
DavidCrow wrote: str.Format(_T("%d:00 %s"), nHour, (nHour >= 12 && nHour <= 23) ? _T("PM") : _T("AM"));
nHour already wrapped to 12, so the checking might be with timecount,
(timecount>= 12 && timecount <= 23)
|
|
|
|
|
Rajkumar R wrote: ...so the checking might be with timecount,
Possibly. I didn't bother verifying this, just started typing.
"Love people and use things, not love things and use people." - Unknown
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
How to know whether our application is focused or not?
|
|
|
|
|
|
Have you looked at GetForegroundWindow() ?
"Love people and use things, not love things and use people." - Unknown
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
Can any body tell me How to get URL of current page?
How can I navigate automatically in a web page.
|
|
|
|
|
Your post is an example of "How not to ask a question". Please read the guidelines^ before you post anything further.
Nobody can give you wiser advice than yourself. - Cicero
.·´¯`·->Rajesh<-·´¯`·.
Codeproject.com: Visual C++ MVP
|
|
|
|
|
Yes U Can ...If U Can ,Dream it , U can do it ...ICAN
|
|
|
|
|
|
sumit.durg wrote: Can any body tell me How to get URL of current page?
Can't you read it? it's always displayed in the address bar of the browser if you don't delete/modify it.
sumit.durg wrote: How can I navigate automatically in a web page.
Try clicking somewhere on the page with your mouse. You might hit a hidden URL
Somethings seem HARD to do, until we know how to do them.
_AnShUmAn_
|
|
|
|
|
Hi to all,
i am using date Timer picker control in my application
at the run time it is displaying current system time
But i want to display my own time , suppose system time is 05:08:07, but i want to display always 10:12:34
that i am doing by using SetFormat function, this function will set this string,
at run time it is displaying 10:12:34,
but the problem is this time is static , i want to modify this time by using up & down arrow ,,
but i can`t ,, arrow keys & up down click buttons are not working
how can i enable arrow keys for changing the time ?
varun
|
|
|
|