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

Problem of using Switch statement to display data in CListBox

Status
Not open for further replies.

Huskey

Vendor
Aug 23, 2002
53
GB
I was trying to display my data in the CListBox like this

checked Time Float(3)
checked Column String
checked Row String

After implementing the switch statement shown below:

int choices = 3;
switch (choices) {
case 1: colTypes == "INTEGER";
case 2: colTypes == "FLOAT";
{
myColumns.Format(_T("%s\t%s"), column, Types);
}
case 3: colTypes == "STRING";
{
myColumns.Format(_T("%s\t%s(%d)"), column, Types, scales);
}
}

I got :
checked Time Float(3)
checked Column String(3)
checked Row String(3)

Can anyone please help me on this..... PLEASE. Thank you


 
I am confused by your use of the switch, and the == operator.

Note 1: you are doing a switch on a fixed number (
Code:
int choices = 3
) (???)

Note 2: the == operator does a comparison. But you use it like an assignment. Are you missing an
Code:
if
?

Note 2b: String comparison / assignment should be done through specific routines, such as strcmp/strcpy. Most strings are either CString objects (which require special attention) or pointers (
Code:
char *
) .

Note 3: I dont see you using
Code:
break;
's in your
Code:
case
statements. This means that even if your
Code:
choices
matches 1, it will also do statements for 2 and 3.
Normally a switch looks like:
Code:
switch (someDecimalVariable) { // int, uint, char, bool, but not float, char *, String etc
  case possiblityA: { ... } break;
  case possiblityB: { ... } break;
  case possiblityC: { ... } break;
  default: { ... }  // In case it doesnt match one of the above.
}

Regards,
Alex
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top