Build error, no message

  • Thread starter Thread starter Phill
  • Start date Start date
P

Phill

I am getting a build error but it doesn't give me an
error message. I know it has to do with the following
line of code. What could be the problem and why don't I
get an error message? Thanks.

for (int i = 0; i <= detailView1.Items.Count - 1; i++)
{
if (detailView1.Items.GetType().ToString().EndsWith
("ItemDateTime"))
{
if advancedList1.SelectedRow[detailView1.Items
.Name].ToString() <> ""

detailView1.Items.Value =
advancedList1.SelectedRow[detailView1.Items.Name]
else

detailView1.Items.Value =
advancedList1.SelectedRow[detailView1.Items.Name]
}
{

detailView1.Items.Value =
advancedList1.SelectedRow[detailView1.Items.Name];

}
}
 
I am getting a build error but it doesn't give me an
error message. I know it has to do with the following
line of code. What could be the problem ...

- Every if-expression must have
parantheses around the condition.

- All sentences must end with semicolon

- In C# we use "!=" instead of "<>"

// Bjorn A
 
Thanks, but still not compiling. Where do I need to
put ; I am a VB programmer converting to C# and am still
learning the syntax.
-----Original Message-----
For starters, I see some "<>" that should be "!="

I am getting a build error but it doesn't give me an
error message. I know it has to do with the following
line of code. What could be the problem and why don't I
get an error message? Thanks.

for (int i = 0; i <= detailView1.Items.Count - 1; i++)
{
if (detailView1.Items.GetType().ToString().EndsWith
("ItemDateTime"))
{
if advancedList1.SelectedRow[detailView1.Items
.Name].ToString() <> ""

detailView1.Items.Value =
advancedList1.SelectedRow[detailView1.Items.Name]
else

detailView1.Items.Value =
advancedList1.SelectedRow[detailView1.Items.Name]
}
{

detailView1.Items.Value =
advancedList1.SelectedRow[detailView1.Items.Name];

}
}



.
 
Thank you. All is good now that I know the rules.
-----Original Message-----

...

- Every if-expression must have
parantheses around the condition.

- All sentences must end with semicolon

- In C# we use "!=" instead of "<>"

// Bjorn A


.
 
Phill said:
I am getting a build error but it doesn't give me an
error message. I know it has to do with the following
line of code. What could be the problem and why don't I
get an error message? Thanks.

for (int i = 0; i <= detailView1.Items.Count - 1; i++)
{

Are you sure you need the -1.

ussually see this when the = sign is not used.

eg
for (int i = 0; i < detailView1.Items.Count - 1; i++) // no = sign.

or
for (int i = 0; i <= detailView1.Items.Count ; i++) // no -1
 
Martin Stainsby said:
Are you sure you need the -1.

ussually see this when the = sign is not used.

eg
for (int i = 0; i < detailView1.Items.Count - 1; i++) // no = sign.

or
for (int i = 0; i <= detailView1.Items.Count ; i++) // no -1

Beers kicking in.......

for (int i = 0; i = detailView1.Items.Count - 1; i++) // no < sign.
or
for (int i = 0; i < detailView1.Items.Count ; i++) // no -1
 
in message...



Are you sure you need the -1.
ussually see this when the = sign is not used.

You're correct that it usually isn't needed, but it is still syntactically
and logically correct code. Your examples are misleading since you've got
them the other way around.

If he wants to iterate through the whole collection, his use of -1 is
correct, but unneccessary, since the following does exactly the same thing,
but with one operation less per iteration (no -1, hence no = sign):

for (int i = 0; i < detailView1.Items.Count; i++)

In your first example he would miss the last item:
for (int i = 0; i < detailView1.Items.Count - 1; i++) // no = sign.

....and in your secon example he would run past the last item...
for (int i = 0; i <= detailView1.Items.Count ; i++) // no -1

....and an Exception would occur.

// Bjorn A
 
Bjorn Abelli said:
In your first example he would miss the last item:


...and in your secon example he would run past the last item...


...and an Exception would occur.

// Bjorn A

Yes I realised this, hence the reply I sent. Although you explain it nicely.
 
Can you please post the entire contents of the build output window and the
task window? It's possible the error message is just scrolling out of view?
 
Back
Top