以文本方式查看主题

-  Foxtable(狐表)  (http://foxtable.com/bbs/index.asp)
--  专家坐堂  (http://foxtable.com/bbs/list.asp?boardid=2)
----  从字符串“Parity.Odd”到类型“Integer”的转换无效。  (http://foxtable.com/bbs/dispbbs.asp?boardid=2&id=170720)

--  作者:shyilin
--  发布时间:2021/8/4 22:16:00
--  从字符串“Parity.Odd”到类型“Integer”的转换无效。
Dim cob1 As WinForm.ComboBox = e.Form.Controls("ComboBox1")\'串口
Dim cob2 As WinForm.ComboBox = e.Form.Controls("ComboBox2")\'波特率
Dim cob3 As WinForm.ComboBox = e.Form.Controls("ComboBox3")\'数据位
Dim cob4 As WinForm.ComboBox = e.Form.Controls("ComboBox4")\'停止位
Dim cob5 As WinForm.ComboBox = e.Form.Controls("ComboBox5")\'效验位
Dim cob6 As WinForm.ComboBox = e.Form.Controls("ComboBox6") \'地址
Dim dr As DataRow = DataTables("INT").DataRows(0)

Ports.Add(cob1.Text)
If Ports(cob1.Text).IsOpen=False Then   
    With Ports(cob1.Text)
        .Close()
        .Encoding=Encoding.ASCII
        .BaudRate = cob2.Text
        .DataBits = cob3.Text
        .Parity = "Parity." & cob5.Text       \'奇效验   值是 odd
        .StopBits = "StopBits." & cob4.Text  \'停止位  1 值是 one
        .Handshake = Handshake.None
        \'.ReadBufferSize() = 8192
        \'.WriteBufferSize() = 4096
        .Open
    End With
end if



上述两个红字要怎么写?

--  作者:有点蓝
--  发布时间:2021/8/5 8:54:00
--  
对象类型是不能直接使用字符串表示的

.Parity = [Enum].Parse(Gettype(Parity), cob5.Text )
--  作者:shyilin8
--  发布时间:2021/8/5 9:06:00
--  
OK! 谢谢老师