don06van

Hi I've been developing a Queue for customers. The user can enter the customer's information into text inputs and add them to the queue, the user can also remove customers from the queue which is where im having problems. I've created array's for all my customers informations and then when they "add to queue" i add it to the datagrid table I have created in the form.

anyways for my remove from queue button here is the code that I have right now and I keep getting errors from it.

Code Snippet

private void removeFromQueueBTN_Click(object sender, EventArgs e)

{

int removeLoc = (int.Parse(removeFromQueueTXT.Text)-1);

anyComments[removeLoc] = "";

posterQueueTable.SelectAll;

posterQueueTable.ClearSelection;

int refreshLoc;

for (refreshLoc = 0; refreshLoc < 1000; refreshLoc++) ;

{

if (anyComments[refreshLoc] == "")

{

statusText.Text += refreshLoc + "has been removed. ";

}

else (refreshLoc >= 0);

{

posterQueueTable.Rows.Add((refreshLoc + 1), customerName[refreshLoc], fileName[refreshLoc], posterWidth[refreshLoc], posterHeight[refreshLoc], numOfCopies[refreshLoc], anyComments[refreshLoc], labStaff[refreshLoc], etA[refreshLoc] + "mins");

}

}

thanks so much i appreciate any help.




Re: Visual C# General Problem with if and else statements within a For Looop. Error CS0201

Ryan Lamansky / Kardax

What line is giving the error

-Ryan / Kardax





Re: Visual C# General Problem with if and else statements within a For Looop. Error CS0201

don06van

Code Snippet

private void removeFromQueueBTN_Click(object sender, EventArgs e)

{

int removeLoc = (int.Parse(removeFromQueueTXT.Text)-1);

anyComments[removeLoc] = "";

posterQueueTable.SelectAll;

posterQueueTable.ClearSelection;

int refreshLoc;

for (refreshLoc = 0; refreshLoc < 1000; refreshLoc++) ;

{

if (anyComments[refreshLoc] == "")

{

statusText.Text += refreshLoc + "has been removed. ";

}

else (refreshLoc >= 0);

{

posterQueueTable.Rows.Add((refreshLoc + 1), customerName[refreshLoc], fileName[refreshLoc], posterWidth[refreshLoc], posterHeight[refreshLoc], numOfCopies[refreshLoc], anyComments[refreshLoc], labStaff[refreshLoc], etA[refreshLoc] + "mins");

}

}

I have bolded and italized everything that was producing an error according to visual stuidoo.

posterQueueTable.SelectAll;

posterQueueTable.ClearSelection;

and

else (refreshLoc >= 0);

produces "only assignment, call, increment, decrementm and new object expressions can be used as a statement."

error: cs0201

for (refreshLoc = 0; refreshLoc < 1000; refreshLoc++) ;

produces "possible mistaken empty statement"

error: CS0642






Re: Visual C# General Problem with if and else statements within a For Looop. Error CS0201

sirjis

SelectAll and ClearSelection are missing the parentheses for a function call. They should be SelectAll() and ClearSelection().

There should be no semicolon at the end of the line "for (refreshLoc = 0; refreshLoc < 1000; refreshLoc++)"





Re: Visual C# General Problem with if and else statements within a For Looop. Error CS0201

don06van

that fixed some of the problems but now I'm still getting an error with that else statement.

I get an error cause of the semi colon so I remove it and then it tells me theres still an error and that I need a semi colon.

So I'm really unsure about how to resolve this issue.






Re: Visual C# General Problem with if and else statements within a For Looop. Error CS0201

Ryan Lamansky / Kardax

An "else" should not be immediately followed by a semi-colon. Remove it and the true problem will present itself.

-Ryan / Kardax





Re: Visual C# General Problem with if and else statements within a For Looop. Error CS0201

sirjis

Oh, missed that...

It should be "else if (refreshLoc >= 0)"

with no semicolon, but the "if" added.




Re: Visual C# General Problem with if and else statements within a For Looop. Error CS0201

Alan M.

There are a quite a few problems.

First, you are calling several methods that take no parameters. You must still however provide parenthesis on these methods.

Fix:

posterQueueTable.ClearSelection();
posterQueueTable.SelectAll();

Second, you are using your "if" statement incorrectly. The correct format looks like.

if (
condition that evaluates to a boolean)
{
// statements
}
else if (condition that evaluates to a boolean)
{
// statements
}
else
{
// statements
}

You may not include the "else if" and/or the "else" blocks if you wish. You have two problems there. First off you are using the "else" block with a condition. The else block is only used if all the conditions in the "if" and "else if" are false, therefore it should have no condition. Instead your code should have been

else if (refreshLoc >= 0)

{

// statements here

}


Last, you also accidentally put a semicolon after your condition. The code below is incorrect because there is a semicolon after the condition. If the compiler allows you to do this, which it will, then your statement or code block following the if statement would always be executed, because you effectively ended the "if" clause after the semicolon (which is right after the condition, meaning you have a blank if statement).


if ( 1 == 1);

Console.WriteLine("yes");



basically, after the key words "if", "else if", or "else" you specify what it is that it should do. What it should do, can either be a single statement or an entire block of statements (using curly braces {}). Most people probably always use the curly braces, specifying a block of code, to remain consistant.


This works fine


if(name.Equals("Alan))

Console.WriteLine("Hello!");

but if I have..

if(name.Equals("Alan))

Console.WriteLine("Hello!");
Console.WriteLine("How are you"); // then this line would always run, it is not in the "if" statement

so then I must do this..

if(name.Equals("Alan")
{
Console.WriteLine("Hello!");
Console.WriteLine("How are you"); // now this only gets executed when my name is alan
}

so you should probably always use the the curly braces {} to specify a block of code after the statement so there is no confusion.



Hope that helps,

Alan

p.s. if it answers your question mark it as the answer










Re: Visual C# General Problem with if and else statements within a For Looop. Error CS0201

micvos

You're giving a next test statement should you should add an ' if' and remove the semicolom.

replace :

else (refreshLoc >= 0);

with:

else if (refreshLoc >= 0)