VB Enum的功能是否与C#中的枚举不同? [英] Does the VB Enum function differently from the enum in C#

查看:74
本文介绍了VB Enum的功能是否与C#中的枚举不同?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,



我正在努力让一些代码正常工作(与VB混乱有关!)

In C#我使用枚举作为决定硬件是否已响应的一种方式。

所以我现在试图在C#中获取我的代码版本以在VB中运行,在C#中我有三个枚举设置

NO_REPLY for not replied

TIMEOUT_REPLY表示未在计时器设置的超时时间内到达的回复

YES_REPLY表示已收到回复



在读取功能中,您将Reply_Status设置为等于否

将数据写入&启动计时器,下面的代码是VB翻译不起作用,但是如果我(可以看到)在其中粘贴一个消息框打印0表示没有回复

并获取数据但是再也不。



Hi All,

I am trying to get some code working (related to the VB mess I winged about!)
In C# I have used enums as a way of deciding if a piece of hardware has responded.
So I am now trying to get a version of my code in C# to function in VB, in C# I have three enums set up
NO_REPLY for Not replied
TIMEOUT_REPLY for a reply that has not arrived in the time out period set by a timer
YES_REPLY for a reply has been received

In the read function you set Reply_Status to be equal to No
write the data out & start the timer the code below is the VB translation which is not working, however if I (as can be seen) stick a message box in it prints up 0 for no reply
and gets the data once but never again.

Reply_Status = REPLY.NO_REPLY
       myComPort.Write(Data_Send)
       MsgBox(Reply_Status)
       While (Reply_Status = REPLY.NO_REPLY)
           NoDataAtPort.Enabled = True
       End While



VB中的枚举可以用这种方式?

格伦


Can the Enums in VB be used this way?
Glenn

推荐答案

他们可以,但这取决于你如何以及在何处设置 Reply_Status 变量,以及你期望从MsgBox看到的值。



显然,应该在你写的这个方法之外确定Reply_Status循环,以便其值可以被另一个线程更改。只是为了确保最好明确地将其确定为REPLY类型(也是REPLY枚举应公开),所以
They can, but it depends a little bit on how and where you set up the Reply_Status variable, and on what value you expect to see from the MsgBox.

Obviously Reply_Status should be determined outside the method where you have written this While loop, so that its value can be changed by another thread. Just to make sure it is best to explicitly determine it as type REPLY (also the REPLY enum should be public), so
Dim Reply_Status As REPLY

Public Reply_Status As REPLY

或类似的东西。



在您的示例代码中,MsgBox将返回Reply_Status变量的整数值。



问候,

Johan

or something like that.

In your example code the MsgBox will return the integer value of the Reply_Status variable.

Regards,
Johan


引用:

道歉,如果这是一个愚蠢的回应。我认为它可以这样使用。但不应该是[While(Reply_Status == REPLY.NO_REPLY)](双等于)



------------- -------------------------------------------------- -----------------

Apologies if it's a stupid response. I think it can be used this way. But shouldn't it be [While (Reply_Status == REPLY.NO_REPLY)] (double equals)

--------------------------------------------------------------------------------



如果您能阅读本文,请致电CoderPanda,收到一封电子邮件说你回答上面的'=='是一个C(ism)用于比较(我先做了那个),但VB把蓝色摇摆的厄运线放在它下面!并说它没有意义(喃喃自语)。


To CoderPanda if you can read this, got an Email saying you replied with above '==' is a C (ism) for comparing (I did that first) but VB put the blue wiggly line of doom below it! and said it didn't make sense(mutter mutter).


这篇关于VB Enum的功能是否与C#中的枚举不同?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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