[Solved]'Cannot implicitly convert type 'string' to 'bool' ? menu

User Tag List

Results 1 to 5 of 5
  1. #1
    -Ryuk-'s Avatar Elite User CoreCoins Purchaser Authenticator enabled
    Reputation
    529
    Join Date
    Nov 2009
    Posts
    1,028
    Thanks G/R
    38/51
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    [Solved]'Cannot implicitly convert type 'string' to 'bool' ?

    Hello, well I have a problem in C# I don't want to have to make a new function for diffrent colours, so I thought the below would work:

    To call it:
    Code:
    msg("0", "hi");
    The function:
    Code:
            public void msg(string msgtype, string Message)
            {
    
                if (msgtype = "o")//0=Red|1=Green|2=Black
                {
                    String res = Message;
                    int selectionStart = richTextBox1.TextLength;
                    richTextBox1.AppendText(res + Environment.NewLine);
                    // OR rtbTestResult.Text += res + Environment.NewLine;
                    richTextBox1.SelectionStart = selectionStart;
                    richTextBox1.SelectionLength = res.Length;
                    richTextBox1.SelectionColor = Color.Red;
                }
            }
    I get the error Error 'Cannot implicitly convert type 'string' to 'bool'

    Any ideas?
    Last edited by -Ryuk-; 12-14-2009 at 10:06 AM.
    |Leacher:11/2009|Donor:02/2010|Established Member:09/2010|Contributor:09/2010|Elite:08/2013|

    [Solved]'Cannot implicitly convert type 'string' to 'bool' ?
  2. #2
    warsheep's Avatar Contributor
    Reputation
    184
    Join Date
    Sep 2006
    Posts
    1,216
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Doesn't it say at which line the error appears?

    edit:

    nvm. Listen to Reid, he actually knows how to read through code. >_>
    Annoyed I didn't see it myself though, rather obvious.
    Last edited by warsheep; 12-14-2009 at 09:57 AM.
    FOR A MOMENT, NOTHING HAPPENED. THEN, AFTER A SECOND OR SO, NOTHING CONTINUED TO HAPPEN.

  3. #3
    ReidE96's Avatar Archer Authenticator enabled
    Reputation
    470
    Join Date
    Dec 2006
    Posts
    1,625
    Thanks G/R
    1/1
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Code:
    if (msgtype == "o")//0=Red|1=Green|2=Black
    You need two == to compare, that way it returns True or False.

  4. #4
    -Ryuk-'s Avatar Elite User CoreCoins Purchaser Authenticator enabled
    Reputation
    529
    Join Date
    Nov 2009
    Posts
    1,028
    Thanks G/R
    38/51
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally Posted by ReidE96 View Post
    Code:
    if (msgtype == "o")//0=Red|1=Green|2=Black
    You need two == to compare, that way it returns True or False.
    Thanks I also noticed that "o" should be "0".

    +Rep
    |Leacher:11/2009|Donor:02/2010|Established Member:09/2010|Contributor:09/2010|Elite:08/2013|

  5. #5
    ReidE96's Avatar Archer Authenticator enabled
    Reputation
    470
    Join Date
    Dec 2006
    Posts
    1,625
    Thanks G/R
    1/1
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally Posted by XAutomation View Post
    Thanks I also noticed that "o" should be "0".

    +Rep
    Well, there's that too, but wasn't so much the issue But there's some optimisation you could do to your code: Use switch (making expandability easier) and set the corresponding colour to a variable. Then just do all your settings at the end, rather than repeating code (and use the new variable).

    Anyway, glad I could help out
    Last edited by ReidE96; 12-14-2009 at 10:13 AM. Reason: Added link for switch.

Similar Threads

  1. Replies: 1
    Last Post: 02-27-2011, 11:11 AM
  2. Cannot type in Mangosd.exe
    By myran2 in forum WoW EMU Questions & Requests
    Replies: 8
    Last Post: 03-18-2009, 08:57 AM
  3. Cannot speak that language!! [SOLVED]
    By kreven in forum World of Warcraft Emulator Servers
    Replies: 3
    Last Post: 01-24-2008, 08:11 AM
  4. Convert any file type in 4 mouse clicks !!!
    By Flying Piggy in forum Community Chat
    Replies: 4
    Last Post: 03-29-2007, 08:43 PM
  5. Some type of new ZG Exploit
    By Filipp in forum World of Warcraft Exploits
    Replies: 6
    Last Post: 07-08-2006, 02:53 AM
All times are GMT -5. The time now is 01:22 AM. Powered by vBulletin® Version 4.2.3
Copyright © 2024 vBulletin Solutions, Inc. All rights reserved. User Alert System provided by Advanced User Tagging (Pro) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
Digital Point modules: Sphinx-based search