I
ian
Hello,
lease can someone give me some advice regarding my program code (simplified
below).
I have an array which is going out of range. I think it's a data type
problem, something which I'm quite new to, (and I suspect the solution is
really simple !)
The program should loop trough the digits in an employee code (empCode).
And then for each of those digits, it should assign a binary code
representation for that digit.
Then it goes on to work with the binary code (this part is fine).
The logic is fine and it works when I explicitly set the employee digit
(empCodeDigit) value to a specific value (1-5) which the program the use to
get to relevent binary code representation for that digit.
I think the problem lies somewhere with the whole "empCode" being a "string"
, and that when I set the empCodeDigit to its 'i'th (Nth) digit (position),
it does not like it (because it is assigning this part of a string to an
"integer", (which it needs to be because that "integer" is then going to be
used as the counter for the "binaryCodes" array)
Thanks for any suggestions.
Ian.
string[] binaryCodes = new string[5]
{"00110","10001","01001","11000","00101"}
string empCode = "12543"; //believe this should be string because could
contain alphanumerics)
//(Will have a test here to check for
alphanumerics and use some other logic)
for (int i = 0; i <= 4; i++)
{
int empCodeDigit = empCode; //thought this would work (but
does not work)
//(should assign a single digit
(1,2,5,4,3) from the empCode)
// int empCodeDigit = 1; // this works (for testing, have
used this simple test
// to explicitly
set the array counter to
// an integer
value)
// empCodeDigit = empCode[1]; // --does not work
//--------------------------------------------------------------------------
---------
// empCodeDigit = empCode[1].ToInt(); // --does not work
// empCodeDigit = byte. empCode[1]; // --does not work
// empCodeDigit = char. empCode[1]; // --does not work
// empCodeDigit = (int) empCode[1]; // --does not work
// empCodeDigit = int (empCode[1]); // --does not work
//--------------------------------------------------------------------------
---------
//(set BinaryString equal to the values in the array, according to the
digit number from the empCode)
string BinaryString = binaryCodes[empCodeDigit]; <----- this array is
going out of range
For (........
{
//(loop through binary code bits)
lease can someone give me some advice regarding my program code (simplified
below).
I have an array which is going out of range. I think it's a data type
problem, something which I'm quite new to, (and I suspect the solution is
really simple !)
The program should loop trough the digits in an employee code (empCode).
And then for each of those digits, it should assign a binary code
representation for that digit.
Then it goes on to work with the binary code (this part is fine).
The logic is fine and it works when I explicitly set the employee digit
(empCodeDigit) value to a specific value (1-5) which the program the use to
get to relevent binary code representation for that digit.
I think the problem lies somewhere with the whole "empCode" being a "string"
, and that when I set the empCodeDigit to its 'i'th (Nth) digit (position),
it does not like it (because it is assigning this part of a string to an
"integer", (which it needs to be because that "integer" is then going to be
used as the counter for the "binaryCodes" array)
Thanks for any suggestions.
Ian.
string[] binaryCodes = new string[5]
{"00110","10001","01001","11000","00101"}
string empCode = "12543"; //believe this should be string because could
contain alphanumerics)
//(Will have a test here to check for
alphanumerics and use some other logic)
for (int i = 0; i <= 4; i++)
{
int empCodeDigit = empCode; //thought this would work (but
does not work)
//(should assign a single digit
(1,2,5,4,3) from the empCode)
// int empCodeDigit = 1; // this works (for testing, have
used this simple test
// to explicitly
set the array counter to
// an integer
value)
// empCodeDigit = empCode[1]; // --does not work
//--------------------------------------------------------------------------
---------
// empCodeDigit = empCode[1].ToInt(); // --does not work
// empCodeDigit = byte. empCode[1]; // --does not work
// empCodeDigit = char. empCode[1]; // --does not work
// empCodeDigit = (int) empCode[1]; // --does not work
// empCodeDigit = int (empCode[1]); // --does not work
//--------------------------------------------------------------------------
---------
//(set BinaryString equal to the values in the array, according to the
digit number from the empCode)
string BinaryString = binaryCodes[empCodeDigit]; <----- this array is
going out of range
For (........
{
//(loop through binary code bits)