|
Thank you for your fast reply.
Ok here's some code. I'm still learning so you may find this utterly simple
In my main window the event gets called:
private void button1_Click(object sender, RoutedEventArgs e)
{
BallEventArgs bEventArgs = new BallEventArgs(Convert.ToInt16(textBox1.Text), Convert.ToInt16(textBox2.Text));
ball.OnBallInPlay(bEventArgs);
}
Then there's e.g. a pitcher class that subscribes to the ball event being raised
public Fan(Ball b)
{
b.BallInPlay += new EventHandler(b_BallInPlay);
}
void b_BallInPlay(object sender, EventArgs e)
{
if (e is BallEventArgs)
{
BallEventArgs bea = e as BallEventArgs;
if (bea.Distance > 400 && bea.Trajectory >30)
{
Homerun();
}
else
{
Cheer();
}
}
Both Homerun and Cheer return a string. It 's that string that I want to display in a textbox called tbOutput in my Window1.
My problem: I can't seem to access the tbOutput textbox from the Homerun and Cheer methods, because tbOutput is private in Window1.
I don't have a clue...
|
|
|
|
|
You should really have asked this in the WPF forum, as WPF experts are more likely to see it there. Anyway, the simple thing to do here is to have a public property that raises a PropertyChanged event (in other words, the class implements the INotifyPropertyChanged interface). Set the DataContext of your view to this instance, and then bind the Text property of your textbox to the property. That should see you done (strictly speaking, you should look into MVVM for this, but that might be too much for you right now)."WPF has many lovers. It's a veritable porn star!" - Josh Smith As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.
My blog | My articles | MoXAML PowerToys | Onyx
|
|
|
|
|
I see no reason for the BallInPlay event. An event is used when you want to be notified by the object that something has happened (Observer pattern). In this case it appears all you want to do is check a result, so just call a method.
private void button1_Click(object sender, RoutedEventArgs e)
{
Pitcher p = new Pitcher();
textbox.text = p.BallInPlay(Convert.ToInt16(textBox1.Text),
Convert.ToInt16 (textBox2.Text));
}
public class Pitcher
{
public string BallInPlay(int distance, int tragetroy)
{
if (distance > 400 && trajectory > 30)
{
return Homerun();
}
else
{
return Cheer();
}
}
} I know the language. I've read a book. - _Madmatt
|
|
|
|
|
Hi,
How can I check if 5 minutes have passed with the datetime object?
I've tried a few things, but none of them worked for me.
Thanks in advance!
|
|
|
|
|
How do you do it as a human being, without computer? Substitute wrist watch for System.DateTime.Now
|
|
|
|
|
I know how... But obviously, I'm doing something wrong.
So I thought another developer could help me out here...
|
|
|
|
|
If you know how to do it, and have tried to get something working, but failed, then tell us about it, describe the concept and implementation, give precise symptoms, and show code if and as needed. Such are the rules of these forums.
|
|
|
|
|
I pass 5 min to this function:
DateTime lastTimeCommandWasUsed = DateTime.MaxValue;
private bool AtLeastXMinutesHavePassed(int xMinutes)
{
DateTime currentTime = DateTime.Now;
bool allowUse = false;
if (lastTimeCommandWasUsed == DateTime.MaxValue)
{
allowUse = true;
}
else
{
TimeSpan elapsedTime = currentTime - lastTimeCommandWasUsed;
allowUse = elapsedTime.TotalMinutes > xMinutes;
}
if (allowUse)
{
lastTimeCommandWasUsed = currentTime;
return true;
}
return false;
}
And it returns very fast 'false'. After debugging it, it seems to check for seconds instead of minutes.
Can't figure out what is going wrong.
|
|
|
|
|
Yustme wrote: it returns very fast
of course it does, there are no loops, no delays, it is just a few statements in a straight line, so it returns "immediately".
Yustme wrote: And it returns ... 'false'
I doubt that.
Yustme wrote: it seems to check for seconds
No way.
I suggest you add logging statements to output the value of relevant variables. Example:
Console.WriteLine("now="+currentTime);
Console.WriteLine("last="+lastTimeCommandWasUsed );
FWIW: unrelated to potential problems, your code would be somewhat simpler if you initialized using MinValue instead of MaxValue!
|
|
|
|
|
I think you miss understood my 'very fast'. Instead of 5 min, 5 sec.
this is the loop, which is not in that function:
private void RestartAfterXMin()<br />
{<br />
<br />
while (this.AtLeastXMinutesHavePassed(5))<br />
{<br />
Thread.Sleep(1000);<br />
<br />
if (this.stopRequested)<br />
return;<br />
}<br />
<br />
this.AutoStop();<br />
Application.Restart();<br />
}
It's initialized with minvalue, nothing changed.
|
|
|
|
|
I suggested to add logging statements and debug.
And I told you MinValue was unrelated to the bug, but would allow for simpler code.
Now solve your problem, don't wait to be spoon fed.
|
|
|
|
|
[quote]
I suggested to add logging statements and debug.
[/quote]
How different would that be when I used the debugger?
[quote]
And I told you MinValue was unrelated to the bug, but would allow for simpler code.
[/quote]
I still expected that something would change, not that it would solve the bug.
[quote]
Now solve your problem, don't wait to be spoon fed.
[/quote]
I could say that programming isn't like boxing, where you tell me a few words like 'you can take him down, you're stronger' while i know i'll get my ass wooped by this guy called Muhammed Ali (hypothetically, i'm fighting him in the ring)..
Instead, you know, a few posts back you pointed me out that there is a quideline for asking questions.
Did you know there is one for 'answering questions' too?
A small quote from that guideline:
[quote]
Insults, slap-downs and sarcasm aren't welcome. Let's work to help developers, not make them feel stupid..
[/quote]
I'm not asking someone to do my work, pointing me in the right direction is more the enough!
|
|
|
|
|
Yustme wrote: How different would that be when I used the debugger?
Logging leaves a trail which makes it easier to spot a pattern, it shows the results automatically for each consecutive run, and it takes virtually no time, whereas using the debugger requires manual intervention and costs seconds per operation, which in a time-related problem often isn't very wise.
Yustme wrote: pointing me in the right direction is more the enough
that is what you got.
|
|
|
|
|
Why not just use a timer?
Set one up so it triggers in 600 seconds, and use the event to set a flag?
Andy
|
|
|
|
|
Your code will never calculate what you want here.
Only for the first time this command is run, the lastTimeCommandWasUsed will be equal to DateTime.MaxValue . hence allowUse is set to true and lastTimeCommandWasUsed is assigned to currentTime .
Now, when you run this command for the second time,
first condition: if (lastTimeCommandWasUsed == DateTime.MaxValue) is false. Hence allowUse is false still.
This the second condition is false too. Hence you get false back.
there is no place where you are returning the value that you seek.
just make one change here. instead of returning false, return "allowUse"
|
|
|
|
|
I run into a little problem I'm not too sure how to get around.
Let's say I have this grammar xml:
<GRAMMAR LANGID="409">
<DEFINE>
<ID NAME="RID_A" VAL="0"></ID>
<ID NAME="RID_B" VAL="1"></ID>
<ID NAME="RID_C" VAL="2"></ID>
<ID NAME="RID_D" VAL="3"></ID>
<ID NAME="RID_E" VAL="8"></ID>
</DEFINE>
<RULE NAME="A" ID="RID_A" TOPLEVEL="ACTIVE">
<P>something</P>
</RULE>
<RULE NAME="B" ID="RID_B" TOPLEVEL="ACTIVE">
<P>go</P>
<P>
<RULEREF REFID="RID_C" />
</P>
</RULE>
<RULE NAME="C" ID="RID_C">
<L PROPID="RID_C">
<P VAL="RID_D">left</P>
<P VAL="RID_E">right</P>
</L>
</RULE>
</GRAMMAR>
So basically, there are 3 commands, "something", "go left", "go right".
Whenever something gets recognized this gets called:
public void RecoContext_Recognition(int StreamNumber, object StreamPosition, SpeechRecognitionType RecognitionType, ISpeechRecoResult e)
Inside of it I'm using a switch switch (e.PhraseInfo.Rule.Name) . For the rules similar to the "something" command, a simple case "A": is all I need.
My issue comes now. For the "go left" or "go right", the case "B": catches them. However, I have no idea how to determine the 'right' or 'left' part of it.
Ideally, this is what I'm looking for.
[ create ] -> one | two | three -> monkeys | elephants | puppies.
Obviously not those examples, but something that follows that path. Can I accomplish that with the sample XML I provided and the switch in the function? Or do I need a different approach?
|
|
|
|
|
is there any body who knows how to implement hand gesture recognition using haarlike features.
I am using AForge.net for image processing.
thanks
|
|
|
|
|
I have Table_A and Table B. Now I want to update all Table_B, column_2 ids with the matching ids in Table_A only. The relationship between
Table_A and Table_B is 1..n.
Could somebody help me to write this query.
Thanks
|
|
|
|
|
1. This is a c# forum. You know, for C# questions
2. If you have posted this on the SQL forum, don't cross post
2. You already know about 1 http://www.codeproject.com/Messages/3284690/question-related-to-homework.aspx[^]
3. Read the FAQs.
4. This is easy to google. I suggest you do that.Dalek Dave: There are many words that some find offensive, Homosexuality, Alcoholism, Religion, Visual Basic, Manchester United, Butter.
Pete o'Hanlon: If it wasn't insulting tools, I'd say you were dumber than a bag of spanners.
|
|
|
|
|
I tried running this query. Is this the right sql query? It seems like it did its job. But, how could i make sure the records have been update properly and i didn't miss any ID in Table_B.
Table_B has thousands of rows. I don't want to go row by row in Table_B to match with Table_A.
I know there must be a better way than doing my way.
update Table_B
set Table_B.Column_2 = Table_A.coulumn_1
from Table_B inner join Table_A on Table_A.Column_1 = Table_B.Column_2
|
|
|
|
|
Still the wrong forum. Dalek Dave: There are many words that some find offensive, Homosexuality, Alcoholism, Religion, Visual Basic, Manchester United, Butter.
Pete o'Hanlon: If it wasn't insulting tools, I'd say you were dumber than a bag of spanners.
|
|
|
|
|
What part of Keiths response did you actually read? You should never use standby on an elephant. It always crashes when you lift the ears. - Mark Wallace
C/C++ (I dont see a huge difference between them, and the 'benefits' of C++ are questionable, who needs inheritance when you have copy and paste) - fat_boy
|
|
|
|
|
Evidently, he only read the signature (which, by the way, needs some spicing up)..45 ACP - because shooting twice is just silly ----- "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997 ----- "The staggering layers of obscenity in your statement make it a work of art on so many levels." - J. Jystad, 2001
|
|
|
|
|
Your query does nothing, in a very expensive fashion, with a typo in your post.
You have joined on Table_A.Column_1 = Table_B.Column_2 and so they already match and the set clause just overwrites the pre-existing value with the same value.
Best to move this to the SQL forum as has been said, however, if the aim is that you have already updated table_A and now want to update the matching records in Table_B this ain't gonna work.
Step 1. Update Table_A, retaining the original IDs in a separate column.
Step 2. Update Table_B, joining on the original IDs and setting the values to the new IDs from Table_A
|
|
|
|
|
|