Jump to content


 


Register a free account to unlock additional features at BleepingComputer.com
Welcome to BleepingComputer, a free community where people like yourself come together to discuss and learn how to use their computers. Using the site is easy and fun. As a guest, you can browse and view the various discussions in the forums, but can not create a new topic or reply to an existing one unless you are logged in. Other benefits of registering an account are subscribing to topics and forums, creating a blog, and having no ads shown anywhere on the site.


Click here to Register a free account now! or read our Welcome Guide to learn how to use this site.

Photo

Probolem In C#?


  • Please log in to reply
12 replies to this topic

#1 Wolfy87

Wolfy87

  • Members
  • 414 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:England
  • Local time:10:37 PM

Posted 14 September 2008 - 11:42 AM

I am making a simple game, well simple to you but its killing my brain :thumbsup:, i have a console screen where all the damage etc and xp are calculated also where it logs its activity but i need to use an if statemeant to say if the text here = the text here (one will be visible = false) The main game.show...i have it all working apart from the if so the game will show even if it dose not = the account name but i cant get the if to work with anything text orentated... heres my code for the login screen, also there is a console screen (works fine) a create accoung screen (works fine) and the main game screen (so far works fine...

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;

namespace DarkMoonv1._0
{
public partial class Login : Form
{
public Login()
{
InitializeComponent();
}

private void button2_Click(object sender, EventArgs e)
{
CreateUser CreateUser = new CreateUser();
CreateUser.Show();
}

private void Login_Load(object sender, EventArgs e)
{
Form1 Form1 = (Form1)Application.OpenForms["Form1"];
Form1.richTextBox1.Text += Environment.NewLine + ("Login Screen Initialized...");
TextReader tr = new StreamReader("AccountName.txt");
textBox2.Text = (tr.ReadLine());
tr.Close();
}

private void button1_Click(object sender, EventArgs e)
{
Form1 Form1 = (Form1)Application.OpenForms["Form1"];
Form1.richTextBox1.Text += Environment.NewLine + (textBox1.Text);
Form1.textBox1.Text = (textBox1.Text);
Form1.richTextBox1.Text += Environment.NewLine + ("Logging In...");
Main Main = new Main();
if (textBox1.Text = textBox2.Text) <<<<<<<<<<<<<<<< Problem!?!?!?!?!?!!?!??!?!!?!?!?!?!?!?!?!?!?!?!?!?!?!?
Main.Show();
this.Close();
}
}
}


Can you help???

BC AdBot (Login to Remove)

 


#2 Wolfy87

Wolfy87
  • Topic Starter

  • Members
  • 414 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:England
  • Local time:10:37 PM

Posted 14 September 2008 - 11:43 AM

I guess its because im trying to use a String when it wants Bool, is that right? if so how do i do it in boolen or bool...whatever -.-

#3 Billy O'Neal

Billy O'Neal

    Visual C++ STL Maintainer


  • Malware Response Team
  • 12,304 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:Redmond, Washington
  • Local time:03:37 PM

Posted 14 September 2008 - 11:58 AM

You're using the assignment operator, not the equality operator.

Do you know the difference between = and ==?

Billy3
Twitter - My statements do not establish the official position of Microsoft Corporation, and are my own personal opinion. (But you already knew that, right?)
Posted Image

#4 Wolfy87

Wolfy87
  • Topic Starter

  • Members
  • 414 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:England
  • Local time:10:37 PM

Posted 14 September 2008 - 04:10 PM

No, But i have seen it used when i was browsing for an awnswer. So is this what you use when saying if this == this when button1_click form2.show (obviosly i wouldnt write it like that though!). So shall i try using == to sort of define it as a string?

#5 sickstrings

sickstrings

  • Members
  • 23 posts
  • OFFLINE
  •  
  • Local time:06:37 AM

Posted 15 September 2008 - 04:11 AM

== is used to compare.
= is used to assign.
There are 10 kinds of people in this world. Those who understand binary and those who don't

Detailed instructions are not meant to insult your intelligence. They are there for readers who may not be familiar with some aspects of their computer.

Roses are #FF0000. Violets are #00FF00. All my base are belong to you.

#6 groovicus

groovicus

  • Security Colleague
  • 9,963 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:Centerville, SD
  • Local time:04:37 PM

Posted 15 September 2008 - 07:02 AM

So shall i try using == to sort of define it as a string?


A comparison operator does not 'define' anything. It compares objects, and that is its only function.

#7 Wolfy87

Wolfy87
  • Topic Starter

  • Members
  • 414 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:England
  • Local time:10:37 PM

Posted 15 September 2008 - 11:59 AM

Ok, sorry my bad wording, i just didnt know how to say what i thought it did :flowers:.

But should i use the == then? if so would it be like this, just to clarify :trumpet:...

private void button1_Click(object sender.EventArgs e)
{
if (textBox1.Text == textBox2.text)
Form2 Form2 = new Form2();
Form2.Show();
}

Or am i entirely (sorry about the spelling) wrong?

Thanks, Wolfy. :thumbsup:

Edited by Wolfy87, 15 September 2008 - 12:00 PM.


#8 groovicus

groovicus

  • Security Colleague
  • 9,963 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:Centerville, SD
  • Local time:04:37 PM

Posted 15 September 2008 - 12:07 PM

You could do it that way, but that code isn't going to do what you think it will. ;)

Incidentally, in many languages, comparing strings using == will not work, because the variable actually holds a pointer to memory. If you have strings in two different locations in memory, even if the strings are identical, they will never be equal because the pointers are not the same (they are holding different addresses). In C#, when strings are compared using the comparison operators, the compiler is smart enough to call the 'equals' method.

#9 Wolfy87

Wolfy87
  • Topic Starter

  • Members
  • 414 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:England
  • Local time:10:37 PM

Posted 15 September 2008 - 01:15 PM

Nope works a treat :flowers: thanks you guys your the best :trumpet:. And it did do what i thought it would do...and more now i get it to write in the console if you loged in succesfully or not :inlove:
Thanks so much, Wolfy.

P.S. do you like my avatar :thumbsup:

#10 groovicus

groovicus

  • Security Colleague
  • 9,963 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:Centerville, SD
  • Local time:04:37 PM

Posted 15 September 2008 - 01:23 PM

And it did do what i thought it would do


Oh? Why dont you see what happens when the inputs are not equal.

#11 Wolfy87

Wolfy87
  • Topic Starter

  • Members
  • 414 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:England
  • Local time:10:37 PM

Posted 15 September 2008 - 01:33 PM

I have, and nothing happens, Why? i dont see a problem with it? You get the username wrong and nothing happens.
Well...Nothing i can see?

Edited by Wolfy87, 15 September 2008 - 01:36 PM.


#12 groovicus

groovicus

  • Security Colleague
  • 9,963 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:Centerville, SD
  • Local time:04:37 PM

Posted 15 September 2008 - 03:44 PM

It will show eventually. I'll leave it as an exercise in programming.

#13 Wolfy87

Wolfy87
  • Topic Starter

  • Members
  • 414 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:England
  • Local time:10:37 PM

Posted 15 September 2008 - 03:59 PM

:S now im worried something catostrophics gunna happen when im playing it lol. How bad will it be because it works fine in debug mode, i dont get what is wrong. this is torture XD




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users