Jump to content
  • Advertisement
Sign in to follow this  
raidzero

C# Chat Program

This topic is 2549 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I'm trying to write a program that replies to user inputs with generic responses. I tried debugging it, but I can't figure out what's wrong.



public partial class FormMain : Form
{
public FormMain()
{
InitializeComponent();
ActiveControl = userInput;
}

public void userInput_TextChanged(object sender, EventArgs e)
{

}

public void chatOutput_TextChanged(object sender, EventArgs e)
{

}

public void btnSend_Click(object sender, EventArgs e)
{
SendMessage();
ActiveControl = userInput;
}

public void SendMessage()
{
Process process = new Process();
process.Processing();
}
}





public class Process
{
FormMain main = new FormMain();
Analyze analyze = new Analyze();

public void Processing()
{
if (main.userInput.Lines.Length >= 1)
{
main.chatOutput.AppendText(main.userInput.Text);
main.chatOutput.AppendText(Environment.NewLine);
}
main.userInput.Text = "";
}
}

Share this post


Link to post
Share on other sites
Advertisement

I tried debugging it, but I can't figure out what's wrong.
[/quote]

We don't know either since you didn't say what the actual problem is.

Well that's not true... The issue is that you're checking a new instance rather than the one with the actual input. But in the future it might not be so obvious.

Share this post


Link to post
Share on other sites
<br />
<br />I tried debugging it, but I can't figure out what's wrong.<br />
<br /><br />We don't know either since you didn't say <i>what the actual problem is.</i><br /><br />Well that's not true... The issue is that you're checking a new instance rather than the one with the actual input. But in the future it might not be so obvious.<br />[/quote]<br /><br /><br />

Sorry I'm still a bit new to programming. How can I reference userInput so I can use it instead of creating a new instance of it?

Share this post


Link to post
Share on other sites

[quote name='Telastyn' timestamp='1324495949' post='4896271']<br />
<br />I tried debugging it, but I can't figure out what's wrong.<br />
<br /><br />We don't know either since you didn't say <i>what the actual problem is.</i><br /><br />Well that's not true... The issue is that you're checking a new instance rather than the one with the actual input. But in the future it might not be so obvious.<br />[/quote]<br /><br /><br />

Sorry I'm still a bit new to programming. How can I reference userInput so I can use it instead of creating a new instance of it?
[/quote]

Something like:

[source lang="csharp"]
public void SendMessage()
{
this.chatOutput.AppendText(Process.UserInput(this.userInput.Text));
this.userInput.Text = string.Empty;
}

public static class Process
{
private static Analyze analyze = new Analyze();

public static string UserInput(string input)
{
return input;
}
}
[/source]

Share this post


Link to post
Share on other sites
How can I use userInput in my Analyze class so I can see if userInput contains certain text?
I have something like this:

FormMain main;

public void Analysis()
{
if (main.userInput.Text.Contains("asdf"))
{

}
}



But how can I reference userInput then analyze it and then modify chatOutput?

Share this post


Link to post
Share on other sites
Something like that, but the errors you're making show a fundamental lack of understanding about how objects are instantiated. Don't try to do too much. I can't help too much without giving code essentially to copy. You need to learn how to construct your program to do what you need.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!