Hi All,
I am trying to replicate a an 'if, then' block in VB that I wrote in C# (That is in my Article Serial Comms in C# for Beginners), the block in C# is:
private string Write_ATE(string Data_To_ATE)
{
string Data_From_ATE = "";
Reply_Status = (int)REPLY.NO_REPLY;
ATEComPort.Write(Data_To_ATE);
while (Reply_Status == (int)REPLY.NO_REPLY)
{
NoDataAtPort.Enabled = true;
}
NoDataAtPort.Enabled = false;
if (Reply_Status == (int)REPLY.TIMEOUT_REPLY)
{
Reply_Status = (int)REPLY.NO_REPLY;
ATEComPort.Write(Data_To_ATE);
while (Reply_Status == (int)REPLY.NO_REPLY)
{
NoDataAtPort.Enabled = true;
}
NoDataAtPort.Enabled = false;
if (Reply_Status == (int)REPLY.TIMEOUT_REPLY)
{
Data_From_ATE = "TIMEOUT";
return (Data_From_ATE);
}
else if (Reply_Status == (int)REPLY.YES_REPLY)
{
Data_From_ATE = ATEComPort.ReadTo("\r\n");
if ((Data_From_ATE.Substring(0, 1)) == (Data_To_ATE.Substring(1, 1)))
{
return (Data_From_ATE);
}
}
else
{
Data_From_ATE = "SERIOUS_ERROR";
return (Data_From_ATE);
}
}
else if (Reply_Status == (int)REPLY.YES_REPLY)
{
Data_From_ATE = ATEComPort.ReadTo("\r\n");
if ((Data_From_ATE.Substring(0, 1)) == (Data_To_ATE.Substring(1, 1)))
{
return (Data_From_ATE);
}
I say it in the Article I'll say it again here, "it's ugly but it seems to work!"
which through some swearing is some more ElseIf I think, I have tried to use the developer fusion tool with out success:
Dim a As Integer
Data_Back = ""
Reply_Status = REPLY.NO_REPLY
TestComPort.Write(Data_Send)
While (Reply_Status = REPLY.NO_REPLY)
TmrNoDataAtPort.Enabled = True
End While
TmrNoDataAtPort.Enabled = False
If (Reply_Status = REPLY.TIMEOUT_REPLY) Then
TestComPort.Write(Data_Send)
Else
While (Reply_Status = REPLY.NO_REPLY)
TmrNoDataAtPort.Enabled = True
End While
TmrNoDataAtPort.Enabled = False
Else If (Reply_Status = REPLY.TIMEOUT_REPLY) Then
Data_Back = "TIMEOUT"
Else if
If (Reply_Status = REPLY.YES_REPLY) Then
Data_Back = TestComPort.ReadTo(Chr(10))
rtbIncoming.Text += Data_Back
End If
End If
The thing is I do not know how to do a multiple if then statement as you would do in C
such as
if(blah = blah)
{
do_stuff
}else if(blah = blah2)
{
do_something_else
}else if(blah = blah3)
{
do_something_else_again
}
in VB is this
if(blah = blah)then
do_stuff
else if (blah = blah2) then
do_something_stuff
else if (blah = blah3) then
do_something_else
end if
Cannot tell if this would work trying again!
Hmmm..., I have this
Dim a As Integer
Data_Back = ""
Reply_Status = REPLY.NO_REPLY
TestComPort.Write(Data_Send)
While (Reply_Status = REPLY.NO_REPLY)
TmrNoDataAtPort.Enabled = True
End While
TmrNoDataAtPort.Enabled = False
If (Reply_Status = REPLY.TIMEOUT_REPLY) Then
TestComPort.Write(Data_Send)
Elseif
While (Reply_Status = REPLY.NO_REPLY)
TmrNoDataAtPort.Enabled = True
End While
TmrNoDataAtPort.Enabled = False
ElseIf (Reply_Status = REPLY.TIMEOUT_REPLY) Then
Data_Back = "TIMEOUT"
ElseIf (Reply_Status = REPLY.YES_REPLY) Then
Data_Back = TestComPort.ReadTo(Chr(10))
rtbIncoming.Text += Data_Back
End If
it appears that the Elseif after the If(Reply_Status = REPLY.TIMEOUT) that is breaking things...
Glenn