Author Topic: Code  (Read 775 times)

0 Members and 1 Guest are viewing this topic.

Offline JakeWindu

  • Contributor
  • New TCC Member
  • *
  • Posts: 13
  • Programmer
    • Meteor
  • Field: Software & Web Development
  • Real Name: Bob Smith
  • Favorite OS: Windows
  • Programming Language: C#
Code
« on: January 31, 2010, 02:21:26 PM »
I was writing code but I got this error: Error   1   Cannot implicitly convert type 'string' to 'System.Windows.Forms.TextBox'   C:\Users\McKinlays Laptop\AppData\Local\Temporary Projects\Spelling Activity\Form1.cs   26   28   Spelling Activity
           

           
Code: [Select]
                 if (textBox2 = "thought") MessageBox.Show("Correct");
                 else MessageBox.Show("Incorrect");

Offline AJ32

  • TCC Webmaster
  • Administrator
  • Cube Head
  • *
  • Posts: 1,403
  • "TCC Fuhrer"
    • Fox Software
  • Field: Software & Web Development
  • Real Name: Andrew Warner
  • Favorite OS: Windows
  • Programming Language: PHP
Re: Code
« Reply #1 on: January 31, 2010, 06:06:55 PM »
You need to call the Text variable part of textBox2:

Code: C# [Select]
  1. textBox2.Text
  2.  

textBox2 is the actual textbox class, that contains more classes and variables, one of which is Text (the text in the textbox). You will also find other classes and variables to change the textbox's properties, such as color and size. If your using Visual Studio, a drop-down with a list of classes and variables should show up once you type the . after textBox2.


Secondly, when using conditional statements (if, else, switch, case, etc.) you need to use the conditional equals sign (==) to compare variables. If you only use one = sign, it will set (in your example) textBox2 equal to "thought" and return true if the set was successful (or false, if not).


Hope this helps! :)

"Data is eternal, immortal, immutable. Even when the engineers and intelligence
behind its creation are gone, information, facts, and knowledge never die."

Offline JakeWindu

  • Contributor
  • New TCC Member
  • *
  • Posts: 13
  • Programmer
    • Meteor
  • Field: Software & Web Development
  • Real Name: Bob Smith
  • Favorite OS: Windows
  • Programming Language: C#
Re: Code
« Reply #2 on: January 31, 2010, 06:11:16 PM »
Cool! Thanks, this helped tons!
It also helped me make a basic log in system :)

Offline AJ32

  • TCC Webmaster
  • Administrator
  • Cube Head
  • *
  • Posts: 1,403
  • "TCC Fuhrer"
    • Fox Software
  • Field: Software & Web Development
  • Real Name: Andrew Warner
  • Favorite OS: Windows
  • Programming Language: PHP
Re: Code
« Reply #3 on: January 31, 2010, 06:16:59 PM »
Great! Glad I could help! :^:

"Data is eternal, immortal, immutable. Even when the engineers and intelligence
behind its creation are gone, information, facts, and knowledge never die."