C# Chat Program

Started by
4 comments, last by Telastyn 12 years, 3 months ago
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 = "";
}
}
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.
<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 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]
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?
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.

This topic is closed to new replies.

Advertisement