Enum(枚举)就是初始化后(不指定就是0),每个增加1。
可以参考:https://learn.microsoft.com/zh-cn/dotnet/visual-basic/language-reference/statements/enum-statement
Public Enum SockState
sckClosed = 0
sckOpen
sckListening
sckConnectionPending
sckResolvingHost
sckHostResolved
sckConnecting
sckConnected
sckClosing
sckError
End Enum
比如你的代码是:
If Winsock1.State <> sckClosed Then Winsock1.Close 'sckClosed=0
是等效的。
在一个有Winsock1控件的代码中:
Private Sub Command1_Click()
Debug.Print sckClosed
Debug.Print sckOpen
Debug.Print sckListening
Debug.Print sckConnectionPending
Debug.Print sckResolvingHost
Debug.Print sckHostResolved
Debug.Print sckConnecting
Debug.Print sckConnected
Debug.Print sckClosing
Debug.Print sckError
End Sub
运行结果:
0
1
2
3
4
5
6
7
8
9