|
ManfredRBihy wrote: Better? Wink
Yes, I am "slightly" more comfotable with timers, so I will give that ago for now.
I am awaighting my new book on c# from amazon so I can get into the learning process better, and hopefully reduce the need to ask so many questions on here.
thank you again
|
|
|
|
|
Aww it didnt work.
It paused but the same thing happned
Steve
|
|
|
|
|
Can you post some code?
That would really be helpful in helping you !
(Remember to use "code block" when posting the code bits.)
|
|
|
|
|
OK, here you go, but please bare in mind I am a learner.
Also, It sort of works now, but the text that is output last is added onto the new text, so I am going wrong somewhere.
This part is elisa (name of the AI reponder)
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
namespace AI
{
class elisa
{
private string input;
private string output;
private int NumberOfReplies = 0;
public string respond(string input)
{
output = ("");
this.input = input;
if (NumberOfReplies >= 1)
{
output = ("Please wait!");
}
else
output = ("Sorry am a bit buzy at the min. ");
NumberOfReplies += 1;
Thread.Sleep(4000);
return output;
}
}
}
And this is from my form, it has a text box to enter what you want to say, and an edit box that then shows that text, and shows the responce from elisa...
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.Threading;
namespace AI
{
public partial class Form1 : Form
{
elisa _elisa = new elisa();
string userInput;
string elisaResponce;
string you = ("You: ");
string elisa = ("Elisa: ");
public Form1()
{
InitializeComponent();
status.Text = ("");
}
private void btnSend_Click(object sender, EventArgs e)
{
updateInput(textBoxInput.Text);
textBoxInput.Clear();
status.Text = ("Elisa is typing a message");
getResponceFromElisa();
}
private void updateInput(string input)
{
richTextBoxOutput.Text += you += input + ("\n");
}
private void getResponceFromElisa()
{
timer1.Start();
}
private void textBoxInput_TextChanged(object sender, EventArgs e)
{
if (textBoxInput.Text == (""))
{
status.Text = ("");
}
else
status.Text = ("You are typing a message...");
}
private void timer1_Tick(object sender, EventArgs e)
{
elisaResponce = _elisa.respond(userInput);
richTextBoxOutput.Text += elisa += elisaResponce;
timer1.Stop();
status.Text = ("");
}
}
}
Thank you for asking to have a look, I appreciate it
Steve
|
|
|
|
|
I'll have a look at your post when I'm home from work.
(And I'm getting ready to go just about now)
Bye for now
|
|
|
|
|
ManfredRBihy wrote: I'll have a look at your post when I'm home from work.
(And I'm getting ready to go just about now)
Thank you
Steve
|
|
|
|
|
your problem lies in elisa.respond() . Inside it lies the folowing code: Thread.Sleep(4000); . You use that method in a Timer.Tick event. So even if timer ticks, the event doesn't finish for next event tick
|
|
|
|
|
this is a quick hack:
try a whateverControl.Refresh() before you put your main thread to sleep.
A thread or timer approach is better though as it would keep your app responsive.
|
|
|
|
|
OK, thank you.
Can you see anywhere in my code why it is that the strings are being added together?
For example, if I type:
Hello.
Then I type hello again, it would output as
hellohello.
I have tried to clear the strings atraight after use but no luck.
Thank you
Steve
|
|
|
|
|
stephen.darling wrote: I have tried to clear the strings atraight after use but no luck
stephen.darling wrote: richTextBoxOutput.Text += you += input + ("\n")
two very strange statements.
|
|
|
|
|
Luc Pattyn wrote: two very strange statements.
Maybe so, but this is me we are talking about, you proberbly know by bow how difficult it is to explain things to you.
You would think, as a Biomedical Scientist that I would not have a issue, but when it comes to a new area, for me, it is
I am awaiting delivery of my new book, head first c#, so hopefully I can start learning properly.
Regards,
Steve
|
|
|
|
|
Here's an extremely cheesy hack. It's only merit (if you can call it that) is that it's quick to write. For grins, you can show/hide a marquee style progress bar before/after calling GenerateResponse() to simulate processing.
string GenerateResponse
(string input)
{
DateTime start = DateTime.Now;
int pause = 3000;
while ((DateTime.Now - start).TotalMilliseconds < pause) {
Application.DoEvents();
}
return "Some response based on " + input;
}
/ravi
|
|
|
|
|
You're a dirty, dirty bird!
|
|
|
|
|
Hence the disclaimers.
If all he wants to do is write a fun little app, it'll do. But I would never put anything like this in my freeware or commercial apps.
/ravi
|
|
|
|
|
How about this?
string GenerateResponse
(string input)
{
DateTime start = DateTime.Now;
int pause = 3000;
loop:
if ((DateTime.Now - start).TotalMilliseconds >= pause) {
return "Some response based on " + input;
}
Application.DoEvents();
goto loop;
}
/ravi
|
|
|
|
|
Now that's just sad, so, so sad
|
|
|
|
|
Go on - 5 it. You know you wanna.
/ravi
|
|
|
|
|
If by "5 it", you mean "punch it in the face with my fist", then I'm sure he does want to.
|
|
|
|
|
Having trouble seeing the smilies?
/ravi
|
|
|
|
|
I too was joking (making reference to hands having 5 fingers). Didn't feel the need to taint the joke with an emotion though.
|
|
|
|
|
I aasigned Text to the Textbox from code behind like "Showing <b>"+Test+" </b> message ...";
Its not displaying Test in bold.How can I do this
|
|
|
|
|
Since you refer to 'code behind' your question is probably in the wrong forum. It should more properly be in (at a guess) the ASP or WPF forum.
In Windows Forms programming the TextBox cannot display text styles from tags, only from being assigned a boldened font.
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
|
|
|
|
|
If you use classic Windows Form App then you need to use TextBox.Font[^]
In Wpf, it is FontWeight
|
|
|
|
|
I aasigned Text to the Textbox from code behind like "Showing "+Test+" message ...";
Its not displaying Test in bold.How can I do this
|
|
|
|
|
Please try to avoid posting the same question more than once!
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
|
|
|
|