473,387 Members | 1,575 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

A constants value expected in switch case

Hi experts, I'm now working on a project to convert vb6 code to c#.net. I am facing a problem when using switch case in side a for loop which concatenating a constant value with for loop counter in the switch case. It tells me an error which is "A constant value expected" but I have no clue about this error and searched quite a long time on internet. Anyone can give me a hint on how to get it solved?

Please see the code belows:

Thanks in advance.

Expand|Select|Wrap|Line Numbers
  1. for (iCount = 1; (iCount <= 2); iCount++) {
  2. oPDSVfei = new VfeiMessage();
  3. // With...
  4.                                                 oPDSVfei.CommandID = oVfei.CommandID;
  5.                                                 oPDSVfei.MachineID = oVfei.MachineID;
  6.                                                 oPDSVfei.MessageType = oVfei.MessageType;
  7.                                                 oPDSVfei.TransactionID = oVfei.TransactionID;
  8.  
  9. for (lPDSItemCnt = 1; (lPDSItemCnt <= oVfei.Count); lPDSItemCnt++) {
  10. switch (oVfei.GetVar(lPDSItemCnt.ToString()).Name) {
  11. case (Constants.ITEM_CARRIER_ID + iCount):
  12.                                                             oPDSVfei.AddVar(Constants.ITEM_CARRIER_ID,VfeiFormat.A,oVfei.GetVar(Constants.ITEM_CARRIER_ID + iCount).Value);       
  13.                                                             break;
  14. case (Constants.ITEM_SLOT_NO + iCount):
  15.                                                             oPDSVfei.AddVar(Constants.ITEM_SLOT_NO,VfeiFormat.U1,oVfei.GetVar(Constants.ITEM_SLOT_NO + iCount).Value);
  16.                                                             break;
  17. case (Constants.ITEM_PORT_ID + iCount):
  18.                                                             oPDSVfei.AddVar(Constants.ITEM_SLOT_NO,VfeiFormat.U1,oVfei.GetVar(Constants.ITEM_PORT_ID + iCount).Value);
  19.                                                             break;
  20. case (Constants.ITEM_CARRIER_ID + ( (iCount == 1) ? 2 : 1 )):
  21. case (Constants.ITEM_SLOT_NO + ( (iCount == 1) ? 2 : 1 )):
  22. case (Constants.ITEM_PORT_ID + ( (iCount == 1) ? 2 : 1 )):
  23.                                                             // The item is another site information
  24.                                                             break;
  25.                                                         default:
  26.                                                             if(!oVfei.GetVar(lPDSItemCnt.ToString()).Value.ToString().Trim() == "") && !oVfei.GetVar(lPDSItemCnt.ToString()).Value.ToString().Trim() == "9999")){
  27.                                                                 oPDSVfei.AddVar(oVfei.GetVar(lPDSItemCnt.ToString()).Name, oVfei.GetVar(lPDSItemCnt.ToString()).Format, oVfei.GetVar(lPDSItemCnt.ToString()).Value);
  28.                                                             }
  29.                                                             break;
  30.                                                     }
  31.                                                 }
  32.  
Mar 15 '18 #1
1 2643
Luuk
1,047 Expert 1GB
You forgot to tell at what line the error is, now the reader has to guess...

Also it's not clear what your code does on line #10
Expand|Select|Wrap|Line Numbers
  1. switch (oVfei.GetVar(lPDSItemCnt.ToString()).Name)
Because we do not have a clue what "OVfei.GetVar(...).Name" is going to do.
Mar 17 '18 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

10
by: Myster Ious | last post by:
Polymorphism replaces switch statements, making the code more compact/readable/maintainable/OO whatever, fine! What I understand, that needs to be done at the programming level, is this: a...
8
by: Richard | last post by:
I am slowly understanding how this all comes together and feel it is an answer to my needs. By using a form with an image as my input, I can assign a value to the image. That I can not do with an...
21
by: Andy | last post by:
Can someone tell me if the following Switch...Case construct is valid? I'm wanting to check for multiple values in the Case statement without explicitly listing each values. So for example, will...
10
by: Chih-Hsu Yen | last post by:
I encountered a strange problem about switch-case statement. switch(cmd) { case 1: statements; break; case 2: statements; break; ... .... case 11: S1; S2; S3; statements;
2
by: Tomas Larsson | last post by:
Hi. I have some problems when using a static readonly declaration of a guid in a switch/case statement. I'll give you an example. public sealed class Activites { private Activites(){}
5
by: sam_cit | last post by:
Hi Everyone, I read somewhere that there are some compile time operations behind switch-case, which is why it can work for cases which evaluates to an integer or character and not strings and...
9
by: sam_cit | last post by:
Hi Everyone, I wanted to know as to how a switch case like the following one is converted into a jump table by the compiler, assuming that it does, switch(i) { case 4 : { ... printf("4");
6
by: asit | last post by:
please modify to get the correct output.(switch case is compulsory) #include <stdio.h> int main() { char ch; printf("Enter any character : "); ch=getch(); switch(ch)
13
by: Satya | last post by:
Hi everyone, This is the first time iam posting excuse me if iam making any mistake. My question is iam using a switch case statement in which i have around 100 case statements to compare. so...
2
by: Annalyzer | last post by:
My form looks like this: <form action="handle_event.php" method="POST" enctype="multipart/form-data"> <table id="event_edit" border="0"> <tr> <td> ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.