473,395 Members | 1,919 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Dumb if question

Bob
In a sub

Private Mysub (string strLang)

{

if (strLang = "FR") Won't compile.

strLang is declared as string in the sub's parameter collection.

I get an error message saying Cannot implicitly convert type 'string' to
'bool'

What am I doing wrong?

Any help would be appreciated

Bob


Aug 11 '06 #1
9 1170
Hello Bob,

Tough time? :)

double == maybe?

BIn a sub
B>
BPrivate Mysub (string strLang)
B>
B{
B>
Bif (strLang = "FR") Won't compile.
B>
BstrLang is declared as string in the sub's parameter collection.
B>
BI get an error message saying Cannot implicitly convert type 'string'
Bto 'bool'
B>
BWhat am I doing wrong?
B>
BAny help would be appreciated
B>
BBob
B>
---
WBR,
Michael Nemtsev :: blog: http://spaces.msn.com/laflour

"At times one remains faithful to a cause only because its opponents do not
cease to be insipid." (c) Friedrich Nietzsche
Aug 11 '06 #2

"Bob" <bd*****@sgiims.comkirjoitti
viestissä:uN**************@TK2MSFTNGP06.phx.gbl...

<snip>
if (strLang = "FR") Won't compile.
Well, change it to

if (strLang == "FR")

and see what happes?

<snip>
Aug 11 '06 #3
What happens? He will tell you that it won't compile because it's written in
VB. There is no "sub" keyword in C# :-)

"cSharpLess" <no@mails.invalidwrote in message
news:eN**************@TK2MSFTNGP02.phx.gbl...
>
"Bob" <bd*****@sgiims.comkirjoitti
viestissä:uN**************@TK2MSFTNGP06.phx.gbl...

<snip>
> if (strLang = "FR") Won't compile.

Well, change it to

if (strLang == "FR")

and see what happes?

<snip>

Aug 11 '06 #4

"Lebesgue" <le******@gmail.comkirjoitti
viestissä:O7**************@TK2MSFTNGP02.phx.gbl...
What happens? He will tell you that it won't compile because it's written
in VB. There is no "sub" keyword in C# :-)
=) Maybe I should go to sleep instead of trying to stubbornly get some code
finished, obviously I'm not really "awake" and working condition anymore :)
Aug 11 '06 #5
"Bob" <bd*****@sgiims.comwrote in message
news:uN**************@TK2MSFTNGP06.phx.gbl...
In a sub
???
What am I doing wrong?

Any help would be appreciated
Well, what language is this, for a start...?
Aug 11 '06 #6

"Lebesgue" <le******@gmail.comkirjoitti
viestissä:O7**************@TK2MSFTNGP02.phx.gbl...
What happens? He will tell you that it won't compile because it's written
in VB. There is no "sub" keyword in C# :-)
hmm, second look on that code... Wouldn't it be

Private Mysub (strLang As string) for VB and not
Private Mysub (string strLang) as he had?
Aug 11 '06 #7
Hi Bob,

in C# = assigns the right value to the left, so strLang = "FR" meansstore "FR" in strLang.
if(strLang) will try to determine if strLang is true or false, and the compiler will complain since a string can't be true or false.

As other have mentioned use == to determine equality and get a boolean value true or false.

The use of capital P in private and sub in the function name might indicate you come from a vb background. C# uses lower case p in private although capital P will work as well.

Furthermore, you will get a compiler error since your method lacks a return value, a sub i C# written as any other method (Subs and Functions are all methods in C#) but with 'void' specified as return value

private void Mysub (string strLang)
{
if (strLang == "FR)
// do something
}

On Fri, 11 Aug 2006 18:22:36 +0200, Bob <bd*****@sgiims.comwrote:
In a sub

Private Mysub (string strLang)

{

if (strLang = "FR") Won't compile.

strLang is declared as string in the sub's parameter collection.

I get an error message saying Cannot implicitly convert type 'string' to
'bool'

What am I doing wrong?

Any help would be appreciated

Bob




--
Happy coding!
Morten Wennevik [C# MVP]
Aug 11 '06 #8
The op's code is CSharp even though he forgot to make "Private" lowercase and refers to the method as a "sub".

Note the "{" and the error referring to "bool".

I bet he was a VB programmer previously since VB only uses one "=".
Private Mysub (string strLang)

{

if (strLang = "FR") Won't compile.

strLang is declared as string in the sub's parameter collection.

I get an error message saying Cannot implicitly convert type 'string' to 'bool'
--
Dave Sexton

"Lebesgue" <le******@gmail.comwrote in message news:O7**************@TK2MSFTNGP02.phx.gbl...
What happens? He will tell you that it won't compile because it's written in VB. There is no "sub" keyword in C# :-)

"cSharpLess" <no@mails.invalidwrote in message news:eN**************@TK2MSFTNGP02.phx.gbl...
>>
"Bob" <bd*****@sgiims.comkirjoitti viestissä:uN**************@TK2MSFTNGP06.phx.gbl...

<snip>
>> if (strLang = "FR") Won't compile.

Well, change it to

if (strLang == "FR")

and see what happes?

<snip>


Aug 11 '06 #9
Bob
Thanks Morten, appreciate the help. You're right I'm used to VB but I try to
be open about it :-)
Like everyone else, I guess I'll end up learning new stuff.
Thanks again
Bob

"Morten Wennevik" <Mo************@hotmail.comwrote in message
news:op.td4p4u0bklbvpo@stone...
Hi Bob,

in C# = assigns the right value to the left, so strLang = "FR" means store
"FR" in strLang.
if(strLang) will try to determine if strLang is true or false, and the
compiler will complain since a string can't be true or false.

As other have mentioned use == to determine equality and get a boolean value
true or false.

The use of capital P in private and sub in the function name might indicate
you come from a vb background. C# uses lower case p in private although
capital P will work as well.

Furthermore, you will get a compiler error since your method lacks a return
value, a sub i C# written as any other method (Subs and Functions are all
methods in C#) but with 'void' specified as return value

private void Mysub (string strLang)
{
if (strLang == "FR)
// do something
}

On Fri, 11 Aug 2006 18:22:36 +0200, Bob <bd*****@sgiims.comwrote:
In a sub

Private Mysub (string strLang)

{

if (strLang = "FR") Won't compile.

strLang is declared as string in the sub's parameter collection.

I get an error message saying Cannot implicitly convert type 'string' to
'bool'

What am I doing wrong?

Any help would be appreciated

Bob




--
Happy coding!
Morten Wennevik [C# MVP]
Aug 11 '06 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

16
by: squash | last post by:
a dumb question i had on my mind: Say you have a dynamically created web page . Isn't it more secure to write it in php since a visitor will not be able to tell it is dynamically created? But...
15
by: Good Man | last post by:
Hey there I have a dumb question.... Let's say i have a database full of 4000 people.... I select everything from the database by: $result = mysql_query("SELECT * FROM People");
3
by: ed | last post by:
I've just started working with .Net, so appologize for what is probably a really dumb question. Did Windows XP originally come with the .Net framework installed, and if so which version? ...
2
by: InvisibleMan | last post by:
Hi, I feel a little dumb for asking this (considering im writing TSQL) but there doesn't seem to be any definitive answers on the search engines... Okay I understand that if you open the ADO...
2
by: TGF | last post by:
How do you copy a String type into a native char buffer? Dumb question, but not sure how to do it :( TGF
5
by: Need Help | last post by:
This might be an extremely dumb question; I'm new to Visual C++, and am trying to use the simple Spooler API, OpenPrinter, but when I try to compile my source file, it says OpenPrinter is an...
10
by: Edward | last post by:
I've just taken over maintaining a system from a colleague who has left. I find the following line in her code: Dim params(2) As SqlClient.SqlParameter params(0) = New...
4
by: Stelrad Doulton | last post by:
Hi, Apologies if this isn't the correct forum. I am writing a communication solution (actually on the Compact Framework) based on HttpWebRequests hooking up with custom handlers on the...
2
by: Bill Nguyen | last post by:
I would like to add a new VB.NET project using the same folder being used by another project so that I can share several forms already creaded by the other project. However, .NET created a new...
6
by: Robert Dufour | last post by:
What is the meaning of the word marshal and unmarshal in plain english as applied to an exe file? Does it mean the application has started and ended? Thanks for any help, Happy new year, Bob
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.