Click here to Skip to main content
15,891,136 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi Frnds

i have 5 textbox in windows form application ,and 1 button.
if buttons clicks textbox value goto excel columns .
but i want if textbox starts with "R" it have to B column in excel. if its starts with "S" it have to go C column in excel.

What I have tried:

In Button i wrote vs2010 to excel converter format.
C#
//In textbox //
  if(textBox1.Text.length==7)  // 7 is a length of textbox //
     textbox2.focus();        // automatically goto next textbox //

and for assign specific rows and columns i try below coding
C#
    int i=0
string str1=BarCode[i].substring[0,1];
       if(str1=="R")
        {
      for(int j=0; j<i;j++)
        {
       if(xlworksheet.cells [j+1,2]==null)
        {
       xlworksheet.cells[j+1,2]=BarCode[i];
break;
       else
       xlworksheet.cells[j+2,2]=BarCode[i];
      }
     }
      else if (str=="S")
     {
     for(int k=0; k<i; k++)
     if(xlworksheet.cells[k+1,3]==null)
    {
xlworksheet.cells[k+1,3]=BarCode[i];
break;
}
else xlworksheet.cells[k+2,3]=BarCode[i];
}
}
}

In this code i didn't get correct format.
frnds pls help me
Posted
Updated 19-Sep-17 19:49pm
v2

We can't tell - too much depends on the content of your data, and when that code actually gets executed: and we have no control over that, nor can we test it here.

So, its going to be up to you.
Put a breakpoint on the first line in the function, and run your code through the debugger. Then look at your code, and at your data and work out what should happen manually. Then single step each line checking that what you expected to happen is exactly what did. When it isn't, that's when you have a problem, and you can back-track (or run it again and look more closely) to find out why.

Sorry, but we can't do that for you - time for you to learn a new (and very, very useful) skill: debugging!
 
Share this answer
 
Advice: learn to properly indent your code, it helps reading as it shows the structure.
C#
int i=0
string str1=BarCode[i].substring[0,1];
if(str1=="R")
{
	for(int j=0; j<i;j++)
	{
		if(xlworksheet.cells [j+1,2]==null)
		{
			xlworksheet.cells[j+1,2]=BarCode[i];
			break;
			else
				xlworksheet.cells[j+2,2]=BarCode[i];
		}
	}
	else if (str=="S")
	{
		for(int k=0; k<i; k++)
			if(xlworksheet.cells[k+1,3]==null)
			{
				xlworksheet.cells[k+1,3]=BarCode[i];
				break;
			}
			else
				xlworksheet.cells[k+2,3]=BarCode[i];
	}
}
}

This do not compile, the structure is wrong.
Advice: do not pack things in a single line of code, any line saved is at the expense of readability.
 
Share this answer
 
v3
Actually no one knows answer my question .....
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900