-
October 20th, 2014, 10:40 AM
#1
C# textChanged problem
Code:
private void txtConsole_TextChanged(object sender, EventArgs e)
{
if ((txtConsole.Text.Contains("STAT")) && (txtConsole.Text.Length > 85))
{
TestRoutine2();
}
}
private void TestRoutine2()
{
string Stat = "";
int Ullage_12cm = 0;
int Sonic_Result_Code_12cm = 0;
int BV_12cm = 0;
int tamb_12cm = 0;
int PassCounter = 0;
int SEss_12cm = 0;
if ((txtConsole.Text.Contains("STAT")) && (txtConsole.Text.Length > 85))
{
string[] splitstring = txtConsole.Text.Split(',');
BV_12cm = Convert.ToInt32(splitstring[2].Replace("BV=", ""));
txtBatteryVoltage.Text = BV_12cm.ToString();
Ullage_12cm = Convert.ToInt32(splitstring[3].Replace("UL=", ""));
txtUllage.Text = Ullage_12cm.ToString();
Sonic_Result_Code_12cm = Convert.ToInt32(splitstring[4].Replace("SRC=", ""));
txtSRC.Text = Sonic_Result_Code_12cm.ToString();
SEss_12cm = Convert.ToInt32(splitstring[5].Replace("SEss=", ""));
txtSESS.Text = SEss_12cm.ToString();
tamb_12cm = Convert.ToInt32(splitstring[6].Replace("TAMB=", ""));
txtTAMB.Text = tamb_12cm.ToString();
Stat = splitstring[9].Replace("STAT=","");
if ((BV_12cm < spnMinBatt.Value) || (Ullage_12cm < SpnSonicLowval.Value - 2) || (Ullage_12cm > SpnSonicLowval.Value + 2) ||
Sonic_Result_Code_12cm < spnSRCLow.Value || (SEss_12cm < spnSEssLow.Value) || ((tamb_12cm < spnTambLow.Value) || (tamb_12cm > spnTambHigh.Value)))
{
txtResultsReading.AppendText("BATT=" + txtBatteryVoltage.Text + " Ullage=" + txtUllage.Text + " SRC=" + txtSRC.Text + " SESS=" + txtSESS.Text + " TAMB=" + txtTAMB.Text + " (FAIL)\r\n");
txtUllage.BackColor = Color.Red;
// PassCounter = 0;//reset pass count
}
else
{
txtResultsReading.AppendText("BATT=" + txtBatteryVoltage.Text + " Ullage=" + txtUllage.Text + " SRC=" + txtSRC.Text + " SESS=" + txtSESS.Text + " TAMB=" + txtTAMB.Text + " (PASS)\r\n");
txtUllage.BackColor = Color.LightGreen;
/*if (++PassCounter >= 6)//increment pass count
{
MessageBox.Show(SpnSonicLowval.Value.ToString() + " cm test passed, now proceed to next test");
}*/
}
}
Application.DoEvents();
/* if (Stat != "0x01")
{
MessageBox.Show("Unit is not in Dormant mode");
MessageBox.Show("Put unit in dormant mode");
}*/
}
Every 2.5 seconds this string is sent to a textbox,which contains sensor values etcADR=0x0100000000,FW=0x010B,BV=26,UL=40,SRC=3,SEss=10,TAMB=73,SQ=32886,STAT=0x03,RFrssi=227
The string updates ok, the if else statements are doing there job but the textboxes containing the values are just staying the same. (txtUllage,txtSRC etc) They update the first time but dont update from their on. Is their something wrong with my loop
-
October 20th, 2014, 01:58 PM
#2
Re: C# textChanged problem
It doesn't look like you are setting txtConsole anywhere. From what I can tell, you set it the first time which causes the text change event to fire, but I don't see where you set the txtConsole again to cause it to re-fire the event.
Also, to help with debugging, put in a Debug.WriteLine statements and look at the output window in the Visual Studio IDE.
-
October 21st, 2014, 02:55 AM
#3
Re: C# textChanged problem
Originally Posted by Arjay
It doesn't look like you are setting txtConsole anywhere. From what I can tell, you set it the first time which causes the text change event to fire, but I don't see where you set the txtConsole again to cause it to re-fire the event.
Also, to help with debugging, put in a Debug.WriteLine statements and look at the output window in the Visual Studio IDE.
How do you set it again. I don't know how to. Thank you for replying
-
October 21st, 2014, 11:46 AM
#4
Re: C# textChanged problem
A user just has to type in that field or you can set it programmatically i.e. txtConsole.Text = "some value";
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|