Reputation: 624
I am converting a vb6 app into c# and I've come across something I don't quite understand. I've never seen an if statement structure where the expression being evaluated is literally "true" or "false".
private bool InitializeForProgramming() //OK
{
if (J1939.getReplyStatus() == modJ1939.dmOpFailed) //or OpComplete (dmBusy auto cycles)
{
//check the Pointer value to see if engineRunning, or already in Mode
if (true) //let it proceed *** ??
{
//nothing to do
}
else
{
lblCommun.Text = "ProgramMode Failed!";
lblCommun.ForeColor = Color.Red;
//could report more detailed reasons! (engineRunning, etc.)
return true; //FAILED!
}
}
What is being evaluated here with the expression if(true)? If what is true?
Here is the original vb6 code:
Private Function InitializeForProgramming() As Boolean 'OK
If getReplyStatus = dmOpFailed Then 'or OpComplete (dmBusy auto cycles)
'check the Pointer value to see if engineRunning, or already in Mode
If (True) Then 'let it proceed *** ??
'nothing to do
Else
txtCommun.Text = "ProgramMode Failed!"
txtCommun.ForeColor = vbRed
'could report more detailed reasons! (engineRunning, etc.)
InitializeForProgramming = True 'FAILED!
Exit Function
End If
End If
Please let me know if you need me to include anything else to help me get an answer.
Upvotes: 2
Views: 135
Reputation: 55
Someone before think that a validation must be done:
//check the Pointer value to see if engineRunning, or already in Mode
Maybe is requirement that hasn't been developed yet.
if (true)
means always, similar to:
if (1 == 1)
Upvotes: 1
Reputation: 26
the if (true) does not mean anything in that case, but it seems like the else is an Exception catch or an OnError.
In C# you should just use a try/catch here.
Upvotes: 1
Reputation: 335
That could not be right, I think that else statement should be outside matching its parent. Otherwise that if (true) was something else before and for debugging reasons was left there as true
Upvotes: 1
Reputation: 388
You are going right man, It is doing nothing by the code if(true) in vb6. Go ahead with your code
Upvotes: 1
Reputation: 354854
Most likely this is the result of a condition that was removed in the past. I.e. there used to be a condition in the if
, but not any longer. You should check the source control history for changes to that line.
You can just remove the whole if
statement in this case for your rewrite. Also C# probably complains that not all code paths return a value from the method.
Upvotes: 7