Int to bool conversion problem
Messages   Related Types
This message was discovered on ASPFriends.com 'aspngfreeforall' list.


Giesbrecht, Jeff
I have a piece of c# code like so:

int numbercols =3D reader.FieldCount; =20
int row =3D 1; =20
while (reader.Read()) {=20
for (int i=3D0;i<numbercols;i++) =20
{
    if (row =3D 1){
        xlsheet.ActiveSheet.Cells[row,i] =3D
reader.GetName(i).ToString();
    }
    else{
        xlsheet.ActiveSheet.Cells[row,i] =3D
reader.GetValue(i).ToString();
    }
}
row++;
}=20

Now VS.NET keeps telling me that the (row =3D 1) portion is wrong =
because
it can't implicitly convert an int to a bool.

I don't know C# just VB and can't figure out how to construct a simple
If then Else statement.
I want the code to check and see if the row =3D 1 then do something, =
else
do something else.

Thanks for the help!!

- Jeff Giesbrecht

Reply to this message...
 
    
chris
if(row == 1){...

= is the 'assignment' operator. C# expects a boolean statement within an if
statement, your previous code was 'assigning' row to equal 1 every time. ==
is a boolean 'assigned to equal'.

-Chris Frazier
.NET Solution Developer
Velocity Databank, Inc.
www.velocitydatabank.com

-----Original Message-----
From: Giesbrecht, Jeff [mailto:Click here to reveal e-mail address]
Sent: Tuesday, August 13, 2002 3:49 PM
To: aspngfreeforall
Subject: [aspngfreeforall] Int to bool conversion problem

I have a piece of c# code like so:

int numbercols = reader.FieldCount;
int row = 1;
while (reader.Read()) {
for (int i=0;i<numbercols;i++)
{
    if (row = 1){
        xlsheet.ActiveSheet.Cells[row,i] =
reader.GetName(i).ToString();
    }
    else{
        xlsheet.ActiveSheet.Cells[row,i] =
reader.GetValue(i).ToString();
    }
}
row++;
}

Now VS.NET keeps telling me that the (row = 1) portion is wrong because
it can't implicitly convert an int to a bool.

I don't know C# just VB and can't figure out how to construct a simple
If then Else statement.
I want the code to check and see if the row = 1 then do something, else
do something else.

Thanks for the help!!

- Jeff Giesbrecht

| ASP.net DOCS = http://www.aspng.com/docs
| [aspngfreeforall] member Click here to reveal e-mail address = YOUR ID
| http://www.asplists.com/aspngfreeforall = JOIN/QUIT
| news://ls.asplists.com = NEWSGROUP

Reply to this message...
 
    
Tim Royal
in c#, the evaluation should be a double equals.

ex: if (row = 1)
becomes
    if (row == 1)

try that and see if it helps.

tim

->-----Original Message-----
->From: Giesbrecht, Jeff [mailto:Click here to reveal e-mail address]
->Sent: Tuesday, August 13, 2002 1:49 PM
->To: aspngfreeforall
->Subject: [aspngfreeforall] Int to bool conversion problem
->
->
->I have a piece of c# code like so:
->
->int numbercols = reader.FieldCount;
->int row = 1;
->while (reader.Read()) {
-> for (int i=0;i<numbercols;i++)
-> {
->    if (row = 1){
->        xlsheet.ActiveSheet.Cells[row,i] ->reader.GetName(i).ToString();
->    }
->    else{
->        xlsheet.ActiveSheet.Cells[row,i] ->reader.GetValue(i).ToString();
->    }
-> }
->row++;
->}
->
->Now VS.NET keeps telling me that the (row = 1) portion is
->wrong because
->it can't implicitly convert an int to a bool.
->
->I don't know C# just VB and can't figure out how to construct a simple
->If then Else statement.
->I want the code to check and see if the row = 1 then do
->something, else
->do something else.
->
->Thanks for the help!!
->
->- Jeff Giesbrecht
->
->| ASP.net DOCS = http://www.aspng.com/docs
->| [aspngfreeforall] member Click here to reveal e-mail address = YOUR ID
->| http://www.asplists.com/aspngfreeforall = JOIN/QUIT
->| news://ls.asplists.com = NEWSGROUP
->
->
Reply to this message...
 
    
Vanegas, Gilbert
Jeff, I believe you need to say
if (row == 1) to make it an equality operator?
I know this works like this in C++.

-----Original Message-----
From: Giesbrecht, Jeff [mailto:Click here to reveal e-mail address]
Sent: Tuesday, August 13, 2002 1:49 PM
To: aspngfreeforall
Subject: [aspngfreeforall] Int to bool conversion problem

I have a piece of c# code like so:

int numbercols = reader.FieldCount;
int row = 1;
while (reader.Read()) {
for (int i=0;i<numbercols;i++)
{
    if (row = 1){
        xlsheet.ActiveSheet.Cells[row,i] =
reader.GetName(i).ToString();
    }
    else{
        xlsheet.ActiveSheet.Cells[row,i] =
reader.GetValue(i).ToString();
    }
}
row++;
}

Now VS.NET keeps telling me that the (row = 1) portion is wrong because
it can't implicitly convert an int to a bool.

I don't know C# just VB and can't figure out how to construct a simple
If then Else statement.
I want the code to check and see if the row = 1 then do something, else
do something else.

Thanks for the help!!

- Jeff Giesbrecht

| ASP.net DOCS = http://www.aspng.com/docs
| [aspngfreeforall] member Click here to reveal e-mail address = YOUR ID
| http://www.asplists.com/aspngfreeforall = JOIN/QUIT
| news://ls.asplists.com = NEWSGROUP

Reply to this message...
 
    
Greg Bernhardt
yes you need ( == )

-----Original Message-----
From: Vanegas, Gilbert [mailto:Click here to reveal e-mail address]
Sent: Tuesday, August 13, 2002 4:30 PM
To: aspngfreeforall
Subject: [aspngfreeforall] RE: Int to bool conversion problem

Jeff, I believe you need to say
if (row == 1) to make it an equality operator?
I know this works like this in C++.

-----Original Message-----
From: Giesbrecht, Jeff [mailto:Click here to reveal e-mail address]
Sent: Tuesday, August 13, 2002 1:49 PM
To: aspngfreeforall
Subject: [aspngfreeforall] Int to bool conversion problem

I have a piece of c# code like so:

int numbercols = reader.FieldCount;
int row = 1;
while (reader.Read()) {
for (int i=0;i<numbercols;i++)
{
    if (row = 1){
        xlsheet.ActiveSheet.Cells[row,i] =
reader.GetName(i).ToString();
    }
    else{
        xlsheet.ActiveSheet.Cells[row,i] =
reader.GetValue(i).ToString();
    }
}
row++;
}

Now VS.NET keeps telling me that the (row = 1) portion is wrong because
it can't implicitly convert an int to a bool.

I don't know C# just VB and can't figure out how to construct a simple
If then Else statement.
I want the code to check and see if the row = 1 then do something, else
do something else.

Thanks for the help!!

- Jeff Giesbrecht

| ASP.net DOCS = http://www.aspng.com/docs
| [aspngfreeforall] member Click here to reveal e-mail address = YOUR ID
| http://www.asplists.com/aspngfreeforall = JOIN/QUIT
| news://ls.asplists.com = NEWSGROUP

| ASP.net DOCS = http://www.aspng.com/docs
| [aspngfreeforall] member Click here to reveal e-mail address = YOUR ID
| http://www.asplists.com/aspngfreeforall = JOIN/QUIT
| news://ls.asplists.com = NEWSGROUP

Reply to this message...
 
    
Tim Musschoot
'=' is the C# assignment operator

Ex: int a = 10;

'==' is a boolean compare operator

Ex: if (a == 10){}

Tim Musschoot
Software Engineer
AspFriends Moderation Team
Click here to reveal e-mail address
http://www.aspalliance.com/timmusschoot

-----Oorspronkelijk bericht-----
Van: Giesbrecht, Jeff [mailto:Click here to reveal e-mail address]
Verzonden: dinsdag 13 augustus 2002 22:49
Aan: aspngfreeforall
Onderwerp: [aspngfreeforall] Int to bool conversion problem

I have a piece of c# code like so:

int numbercols = reader.FieldCount;
int row = 1;
while (reader.Read()) {
for (int i=0;i<numbercols;i++)
{
    if (row = 1){
        xlsheet.ActiveSheet.Cells[row,i] =
reader.GetName(i).ToString();
    }
    else{
        xlsheet.ActiveSheet.Cells[row,i] =
reader.GetValue(i).ToString();
    }
}
row++;
}

Now VS.NET keeps telling me that the (row = 1) portion is wrong because
it can't implicitly convert an int to a bool.

I don't know C# just VB and can't figure out how to construct a simple
If then Else statement. I want the code to check and see if the row = 1
then do something, else do something else.

Thanks for the help!!

- Jeff Giesbrecht

| ASP.net DOCS = http://www.aspng.com/docs
| [aspngfreeforall] member Click here to reveal e-mail address = YOUR ID
| http://www.asplists.com/aspngfreeforall = JOIN/QUIT
| news://ls.asplists.com = NEWSGROUP

Reply to this message...
 
    
Light, Barney
Correct c# operator for an equality test is '=='. So the line should read:

if (row == 1)

The '=' operator is only used for assignment.

hth,

barney.

-----Original Message-----
From: Giesbrecht, Jeff [mailto:Click here to reveal e-mail address]
Sent: 13 August 2002 21:49
To: aspngfreeforall
Subject: [aspngfreeforall] Int to bool conversion problem

I have a piece of c# code like so:

int numbercols = reader.FieldCount;
int row = 1;
while (reader.Read()) {
for (int i=0;i<numbercols;i++)
{
    if (row = 1){
        xlsheet.ActiveSheet.Cells[row,i] =
reader.GetName(i).ToString();
    }
    else{
        xlsheet.ActiveSheet.Cells[row,i] =
reader.GetValue(i).ToString();
    }
}
row++;
}

Now VS.NET keeps telling me that the (row = 1) portion is wrong because
it can't implicitly convert an int to a bool.

I don't know C# just VB and can't figure out how to construct a simple
If then Else statement.
I want the code to check and see if the row = 1 then do something, else
do something else.

Thanks for the help!!

- Jeff Giesbrecht

| ASP.net DOCS = http://www.aspng.com/docs
| [aspngfreeforall] member Click here to reveal e-mail address = YOUR ID
| http://www.asplists.com/aspngfreeforall = JOIN/QUIT
| news://ls.asplists.com = NEWSGROUP

Reply to this message...
 
 




Ad
MBR BootFX
Best-of-breed application framework for .NET projects, developed by Matthew Baxter-Reynolds and MBR IT
 
 Copyright © Matthew Baxter-Reynolds 2001-2008. '.NET 247 Software Development Services' is a trading style of MBR IT Solutions Ltd.
Contact Us - Terms of Use - Privacy Policy - www.dotnet247.com