4 Replies - 406 Views - Last Post: 25 July 2012 - 07:46 AM Rate Topic: -----

#1 Derek1356  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 22-July 12

C# log in page problem?

Posted 22 July 2012 - 11:44 AM

OK, I'm fairly new to C#, and am trying to set up a log in page to bring you to form2 if your username and password is correct. My problem is, is I get two errors saying 'Cannot implicitly convert type 'string' to 'bool' '. Here's my code :

      bool username = true;
            bool password = true;


            username = (userName.Text);
            password = (password1.Text);

            if (username == true && password == true);
            {
                
            }
        }	

What am I doing wrong? Can anyone help? And also, what's the code to 'If all these are true, go to Form2? As stated I'm new to C# and needed help.

Is This A Good Question/Topic? 0
  • +

Replies To: C# log in page problem?

#2 Skydiver  Icon User is offline

  • Code herder
  • member icon

Reputation: 3565
  • View blog
  • Posts: 11,074
  • Joined: 05-May 12

Re: C# log in page problem?

Posted 22 July 2012 - 12:30 PM

On lines 5 and 6, you are trying to assign strings (eg. userName.Text, password1.Text) to a bool. As the compiler said, it can't figure out how automatically convert a string to a boolean.

It's like trying to do this:
bool isBlue = "red";    // !!! Compilation error



What you want to do is do a comparison using a comparison operator. Comparison operators will return a bool.

bool isBlue = ("red" == "Blue");



As for bringing up a second form, how did you bring up the first form?
Was This Post Helpful? 1
  • +
  • -

#3 Derek1356  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 22-July 12

Re: C# log in page problem?

Posted 22 July 2012 - 12:42 PM

Well, as for bringing up the form, I use the Visual C#.NET version, that might be in the core code that's pre wrote on a project. I know in VB.NET it's something like
form2.Show
But still thanks for the help.
Was This Post Helpful? 0
  • +
  • -

#4 Curtis Rutland  Icon User is online

  • (╯□)╯︵ (~ .o.)~
  • member icon


Reputation: 4479
  • View blog
  • Posts: 7,801
  • Joined: 08-June 10

Re: C# log in page problem?

Posted 23 July 2012 - 08:06 AM

VB.NET lets you cheat, by using a default instance. So you can use Form names as if they were static. C# does not.

If you want to show a new form, you must create a new form:

Form2 f2 = new Form2();
f2.Show();
//f2.ShowDialog();


Getting data from Form1 to Form2
Was This Post Helpful? 0
  • +
  • -

#5 Derek1356  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 22-July 12

Re: C# log in page problem?

Posted 25 July 2012 - 07:46 AM

View PostCurtis Rutland, on 23 July 2012 - 08:06 AM, said:

VB.NET lets you cheat, by using a default instance. So you can use Form names as if they were static. C# does not.

If you want to show a new form, you must create a new form:

Form2 f2 = new Form2();
f2.Show();
//f2.ShowDialog();


Getting data from Form1 to Form2


Thanks so much for that. I'm still having a few errors on the last help but I'll work on it myself for another week or two before I ask for help again.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1