Need to time stamp the last time a file was considered good. [modified]
-
Need to time stamp the last time a file was considered good. I was trying to use something like: last_Time = DateTime.Now;. This is used inside a decision block. The problem even if the condition to enter the particular block isn't met, it still updates. So does DateTime.Now execute no matter what? Now for what I really need. I need to timestamp a infopacket/file/situation as to the last time it passed inspection. In other words when was the last good infopacket/file/situation. The following code is what I thought would work:
public static DateTime last_Time;
public void Packet_Check(int decision)
{ /* checks for last good info packet. checks from lightest to most sever.
* if decision = 0, add 1 to pass_counter
* if decision = 1, pass_counter = 0, good packet and timestamps
*/
/*
int pass_marker = 0;// make global
int pass_counter = 0;// make global
int first_check = 0; // make global bool used if first pass made
*/
pass_counter++;
if (decision == 1)
{
stateIndicatorComponent2.StateIndex = 4;
pass_counter = 0;
last_Time = DateTime.Now; // <<<<<<<< EXECUTES EVERY PASS, aargh!!!!!!!!!
TRUCK_ID_DISPLAY.BackColor = Color.White;
Performance_Log_File(this.Name, Convert.ToString(last_Time)+ " last good packet " + port_in );
}
else
{
if (pass_counter > 3) //change to yellow
{
stateIndicatorComponent2.StateIndex = 3;
//pass_counter++;
}if (pass\_counter > 7) // red { stateIndicatorComponent2.StateIndex = 2; //red //pass\_counter++; //Diag\_Box.Text = " Last Entry -- " + last\_Time + "\\r\\n " + File\_Write\_Hold; } if (pass\_counter > 12) // red with warning message { //mess sent to operator Diag\_Box.Text = "lastime is " + last\_Time; //Diag\_Box.Text = pass\_counter + " " +this.Name + " has failed to recv good info/packetsince " + last\_Time + " check all input!!!!"; if (light == true) { stateIndicatorComponent2.StateIndex = 3;
-
Need to time stamp the last time a file was considered good. I was trying to use something like: last_Time = DateTime.Now;. This is used inside a decision block. The problem even if the condition to enter the particular block isn't met, it still updates. So does DateTime.Now execute no matter what? Now for what I really need. I need to timestamp a infopacket/file/situation as to the last time it passed inspection. In other words when was the last good infopacket/file/situation. The following code is what I thought would work:
public static DateTime last_Time;
public void Packet_Check(int decision)
{ /* checks for last good info packet. checks from lightest to most sever.
* if decision = 0, add 1 to pass_counter
* if decision = 1, pass_counter = 0, good packet and timestamps
*/
/*
int pass_marker = 0;// make global
int pass_counter = 0;// make global
int first_check = 0; // make global bool used if first pass made
*/
pass_counter++;
if (decision == 1)
{
stateIndicatorComponent2.StateIndex = 4;
pass_counter = 0;
last_Time = DateTime.Now; // <<<<<<<< EXECUTES EVERY PASS, aargh!!!!!!!!!
TRUCK_ID_DISPLAY.BackColor = Color.White;
Performance_Log_File(this.Name, Convert.ToString(last_Time)+ " last good packet " + port_in );
}
else
{
if (pass_counter > 3) //change to yellow
{
stateIndicatorComponent2.StateIndex = 3;
//pass_counter++;
}if (pass\_counter > 7) // red { stateIndicatorComponent2.StateIndex = 2; //red //pass\_counter++; //Diag\_Box.Text = " Last Entry -- " + last\_Time + "\\r\\n " + File\_Write\_Hold; } if (pass\_counter > 12) // red with warning message { //mess sent to operator Diag\_Box.Text = "lastime is " + last\_Time; //Diag\_Box.Text = pass\_counter + " " +this.Name + " has failed to recv good info/packetsince " + last\_Time + " check all input!!!!"; if (light == true) { stateIndicatorComponent2.StateIndex = 3;
DateTime.Now is a static property that will always return a DateTime set to the current system's time.
Dave
BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)
Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia)
Why are you using VB6? Do you hate yourself? (Christian Graus) -
Need to time stamp the last time a file was considered good. I was trying to use something like: last_Time = DateTime.Now;. This is used inside a decision block. The problem even if the condition to enter the particular block isn't met, it still updates. So does DateTime.Now execute no matter what? Now for what I really need. I need to timestamp a infopacket/file/situation as to the last time it passed inspection. In other words when was the last good infopacket/file/situation. The following code is what I thought would work:
public static DateTime last_Time;
public void Packet_Check(int decision)
{ /* checks for last good info packet. checks from lightest to most sever.
* if decision = 0, add 1 to pass_counter
* if decision = 1, pass_counter = 0, good packet and timestamps
*/
/*
int pass_marker = 0;// make global
int pass_counter = 0;// make global
int first_check = 0; // make global bool used if first pass made
*/
pass_counter++;
if (decision == 1)
{
stateIndicatorComponent2.StateIndex = 4;
pass_counter = 0;
last_Time = DateTime.Now; // <<<<<<<< EXECUTES EVERY PASS, aargh!!!!!!!!!
TRUCK_ID_DISPLAY.BackColor = Color.White;
Performance_Log_File(this.Name, Convert.ToString(last_Time)+ " last good packet " + port_in );
}
else
{
if (pass_counter > 3) //change to yellow
{
stateIndicatorComponent2.StateIndex = 3;
//pass_counter++;
}if (pass\_counter > 7) // red { stateIndicatorComponent2.StateIndex = 2; //red //pass\_counter++; //Diag\_Box.Text = " Last Entry -- " + last\_Time + "\\r\\n " + File\_Write\_Hold; } if (pass\_counter > 12) // red with warning message { //mess sent to operator Diag\_Box.Text = "lastime is " + last\_Time; //Diag\_Box.Text = pass\_counter + " " +this.Name + " has failed to recv good info/packetsince " + last\_Time + " check all input!!!!"; if (light == true) { stateIndicatorComponent2.StateIndex = 3;
X|
Luc Pattyn [Forum Guidelines] [My Articles]
The quality and detail of your question reflects on the effectiveness of the help you are likely to get. Show formatted code inside PRE tags, and give clear symptoms when describing a problem.
-
X|
Luc Pattyn [Forum Guidelines] [My Articles]
The quality and detail of your question reflects on the effectiveness of the help you are likely to get. Show formatted code inside PRE tags, and give clear symptoms when describing a problem.
-
DateTime.Now is a static property that will always return a DateTime set to the current system's time.
Dave
BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)
Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia)
Why are you using VB6? Do you hate yourself? (Christian Graus) -
much better. Now I'll read it. :)
Luc Pattyn [Forum Guidelines] [My Articles]
The quality and detail of your question reflects on the effectiveness of the help you are likely to get. Show formatted code inside PRE tags, and give clear symptoms when describing a problem.
-
Need to time stamp the last time a file was considered good. I was trying to use something like: last_Time = DateTime.Now;. This is used inside a decision block. The problem even if the condition to enter the particular block isn't met, it still updates. So does DateTime.Now execute no matter what? Now for what I really need. I need to timestamp a infopacket/file/situation as to the last time it passed inspection. In other words when was the last good infopacket/file/situation. The following code is what I thought would work:
public static DateTime last_Time;
public void Packet_Check(int decision)
{ /* checks for last good info packet. checks from lightest to most sever.
* if decision = 0, add 1 to pass_counter
* if decision = 1, pass_counter = 0, good packet and timestamps
*/
/*
int pass_marker = 0;// make global
int pass_counter = 0;// make global
int first_check = 0; // make global bool used if first pass made
*/
pass_counter++;
if (decision == 1)
{
stateIndicatorComponent2.StateIndex = 4;
pass_counter = 0;
last_Time = DateTime.Now; // <<<<<<<< EXECUTES EVERY PASS, aargh!!!!!!!!!
TRUCK_ID_DISPLAY.BackColor = Color.White;
Performance_Log_File(this.Name, Convert.ToString(last_Time)+ " last good packet " + port_in );
}
else
{
if (pass_counter > 3) //change to yellow
{
stateIndicatorComponent2.StateIndex = 3;
//pass_counter++;
}if (pass\_counter > 7) // red { stateIndicatorComponent2.StateIndex = 2; //red //pass\_counter++; //Diag\_Box.Text = " Last Entry -- " + last\_Time + "\\r\\n " + File\_Write\_Hold; } if (pass\_counter > 12) // red with warning message { //mess sent to operator Diag\_Box.Text = "lastime is " + last\_Time; //Diag\_Box.Text = pass\_counter + " " +this.Name + " has failed to recv good info/packetsince " + last\_Time + " check all input!!!!"; if (light == true) { stateIndicatorComponent2.StateIndex = 3;
Hi, the code shown has only one way to modify last_Time. If you are not satisfied with the value of last_Time, AFAIK there are only two possibilities: 1. Check(1) is called where Check(0) was intended, causing the block with "ast_Time=now" to execute. 2. More Check(1) calls are performed, maybe entirely unrelated to the ones you are looking at, but since last_Time is static, they all share that one variable. Suggestions: 1. don't use static variables unless you really need them; when they just seem the easy way to solve something, they will come back at you later on. A better way would be to make them non-static and instantiate your class once for every independent series of checks you want to perform (you already have to instantiate since Check itself is not static). 2. choose better names for your variables, especially the class members (last_Time) and the method parameters (decision). Also use boolean type if only two values are allowed, use an enum when more than two non-counting values are acceptable. Instead of
if(decision==1) ...
I would writeif (packetOK) ...
orif (packetState==PacketState.Good)...
:)Luc Pattyn [Forum Guidelines] [My Articles]
The quality and detail of your question reflects on the effectiveness of the help you are likely to get. Show formatted code inside PRE tags, and give clear symptoms when describing a problem.
-
Hi, the code shown has only one way to modify last_Time. If you are not satisfied with the value of last_Time, AFAIK there are only two possibilities: 1. Check(1) is called where Check(0) was intended, causing the block with "ast_Time=now" to execute. 2. More Check(1) calls are performed, maybe entirely unrelated to the ones you are looking at, but since last_Time is static, they all share that one variable. Suggestions: 1. don't use static variables unless you really need them; when they just seem the easy way to solve something, they will come back at you later on. A better way would be to make them non-static and instantiate your class once for every independent series of checks you want to perform (you already have to instantiate since Check itself is not static). 2. choose better names for your variables, especially the class members (last_Time) and the method parameters (decision). Also use boolean type if only two values are allowed, use an enum when more than two non-counting values are acceptable. Instead of
if(decision==1) ...
I would writeif (packetOK) ...
orif (packetState==PacketState.Good)...
:)Luc Pattyn [Forum Guidelines] [My Articles]
The quality and detail of your question reflects on the effectiveness of the help you are likely to get. Show formatted code inside PRE tags, and give clear symptoms when describing a problem.