VB.Net系统计时器无法按预期工作 [英] VB.Net System timers not working as expected

查看:106
本文介绍了VB.Net系统计时器无法按预期工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,



我试图在VB中复制一个'if,then'块我用C#写的(那是在我的文章串口通讯中)在C#for Beginners中,C#中的块是:



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);
       }





我在文章中说它我会在这里再说一遍,这很难看,但似乎有效!

通过一些咒骂更多ElseIf我认为,我试图使用开发人员融合工具取得成功:







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





事情是我不知道怎么做多重if if then语句正如您在C

中所做的那样,例如



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





a a a在Ifse之后的Elseif(Reply_Status = REPLY.TIMEOUT)破坏了东西......





格伦



it appears that the Elseif after the If(Reply_Status = REPLY.TIMEOUT) that is breaking things...


Glenn

推荐答案

你注意到 blah = blah 总是返回true,这会使你的的所有其他分支成立无法访问?

-SA
Did you notice blah = blah always returns true, which makes all other branched of your if unreachable?
—SA


这篇关于VB.Net系统计时器无法按预期工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆