.net 数据操作和转换

.net 数据操作和转换,.net,vb.net,serial-port,.net,Vb.net,Serial Port,我有八个文本框,每个文本框可以有任何数值,每个数值只能由数字1-8组成,最多八位数字。没有0或9 我正在使用计时器以给定的速率在文本框序列中循环。这已经配置好了 现在是最难的部分 我需要输出一个文本框的第一个值,等待一段时间,然后输出它的计数器字母(在键盘上的数字下方),转到下一个文本框并重复。例如: 我的八个盒子里有: 1 34 765 2 56 84 7 12345678 发送“124”将打开通道1、2和4。 发送“QWR”将关闭通道1、2和4 我只写了几天的代码,所以放松点。边走边学。 我

我有八个文本框,每个文本框可以有任何数值,每个数值只能由数字1-8组成,最多八位数字。没有0或9

我正在使用计时器以给定的速率在文本框序列中循环。这已经配置好了

现在是最难的部分

我需要输出一个文本框的第一个值,等待一段时间,然后输出它的计数器字母(在键盘上的数字下方),转到下一个文本框并重复。例如:

我的八个盒子里有:

1 34 765 2 56 84 7 12345678 发送“124”将打开通道1、2和4。 发送“QWR”将关闭通道1、2和4

我只写了几天的代码,所以放松点。边走边学。 我的建议可供参考

最终,我尝试通过从并行端口到USB来更新我的设备。这将是设备的“自定义循环”功能

Dim loopnum1 As String
        loopnum1 = TxtLoop1.Text
        Dim ListOfloop1 As String() = loopnum1.Split(New Char() {""})
        Dim singlenum1 As String
        Dim offloop1 As String
        offloop1 = "Q"
        For Each singlenum1 In ListOfloop1
            SerialPort1.Write(singlenum1)
            Timer2.Interval = (cmbSPLoop.Value) * 12
            If singlenum1 = "1" Then offloop1 = "Q"
            If singlenum1 = "2" Then offloop1 = "W"
            If singlenum1 = "3" Then offloop1 = "E"
            If singlenum1 = "4" Then offloop1 = "R"
            If singlenum1 = "5" Then offloop1 = "T"
            If singlenum1 = "6" Then offloop1 = "Y"
            If singlenum1 = "7" Then offloop1 = "U"
            If singlenum1 = "8" Then offloop1 = "I"
            SerialPort1.Write(offloop1)
        Next
        Dim loopnum2 As String
        loopnum2 = TxtLoop2.Text
        Dim ListOfloop2 As String() = loopnum2.Split(New Char() {""})
        Dim singlenum2 As String
        Dim offloop2 As String
        offloop2 = "Q"
        For Each singlenum2 In ListOfloop2
            SerialPort1.Write(singlenum2)
            Timer2.Interval = (cmbSPLoop.Value) * 12
            If singlenum2 = "1" Then offloop2 = "Q"
            If singlenum2 = "2" Then offloop2 = "W"
            If singlenum2 = "3" Then offloop2 = "E"
            If singlenum2 = "4" Then offloop2 = "R"
            If singlenum2 = "5" Then offloop2 = "T"
            If singlenum2 = "6" Then offloop2 = "Y"
            If singlenum2 = "7" Then offloop2 = "U"
            If singlenum2 = "8" Then offloop2 = "I"
            SerialPort1.Write(offloop2)
        Next
等等


我想我要么一行做八次,每次增加TxtLoop#.text或者?

我要么一行做八次,每次增加TxtLoop#.text或者?

我认为您应该尝试一个嵌套循环,而不是在8个文本框中输出每个字符的8个循环

Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
        OutputToSerialPort()
    End Sub


Private Sub OutputToSerialPort()
    Dim txt = New TextBox
    For index As Integer = 1 To 8
        txt = FindControl(GroupBox1.Controls, "TextBox" & index)
        Dim ListOfloop As Char() = txt.Text.ToCharArray()  '<- edits on this line
        Dim singlenum As String
        Dim offloop As String
        offloop = "Q"
        For Each singlenum In ListOfloop
            'SerialPort1.Write(singlenum)
            'Timer2.Interval = (cmbSPLoop.Value) * 12
            If singlenum = "1" Then offloop = "Q"
            If singlenum = "2" Then offloop = "W"
            If singlenum = "3" Then offloop = "E"
            If singlenum = "4" Then offloop = "R"
            If singlenum = "5" Then offloop = "T"
            If singlenum = "6" Then offloop = "Y"
            If singlenum = "7" Then offloop = "U"
            If singlenum = "8" Then offloop = "I"
            'SerialPort1.Write(offloop)
        Next
    Next index
End Sub

Public Function FindControl(ByVal oControls As Control.ControlCollection,
ByVal strControlName As String) As Control
    Dim MyCtl As Control

    For Each MyCtl In oControls
        If MyCtl.Name = strControlName Then
            Return MyCtl
        Else
            If MyCtl.Controls.Count > 0 Then
                Return FindControl(MyCtl.Controls, strControlName)
            End If
        End If
    Next
    Return Nothing
End Function
Private子按钮1\u单击(发送方作为System.Object,e作为System.EventArgs)处理按钮1。单击
OutputOSerialPort()
端接头
专用子输出SerialPort()
Dim txt=新文本框
对于作为整数的索引=1到8
txt=FindControl(GroupBox1.Controls、“TextBox”和索引)

Dim ListOfloop As Char()=txt.Text.ToCharArray()'您的问题不是很清楚。您是否有特定的问题,或者您是否正在寻求关于如何实施此项目的一般建议?这是一个很棒的项目。我想询问者想知道如何回放数字和字母的序列,并将它们发送到串行端口。@BrianWillis Mpelletier有这个想法。这是一个非常粗略的代码概念。我可能已经完全关机了。这是DLP-IO8的链接-你怎么处理这个Scott?我有一个自定义环路的开始/停止按钮,所以我需要一个由Timer2控制的速度控制延迟。间隔=(cmbSPLoop.Value)*12cmbSPLoop从1到10。我的延迟时间是12点,因为我认为我必须重复这些步骤。我应该澄清一下:我只是用定时器和串行输出注释掉了代码行,这样它就可以编译了(在我的IDE中)。请取消对这些行的注释,忘记按钮clickObject引用未设置为对象的实例。更改该行比我的表单-txt=FindControl(GroupBox3.Controls,“TxtLoop”和index)快得多
Dim loopnum1 As String
        loopnum1 = TxtLoop1.Text
        Dim ListOfloop1 As String() = loopnum1.Split(New Char() {""})
        Dim singlenum1 As String
        Dim offloop1 As String
        offloop1 = "Q"
        For Each singlenum1 In ListOfloop1
            SerialPort1.Write(singlenum1)
            Timer2.Interval = (cmbSPLoop.Value) * 12
            If singlenum1 = "1" Then offloop1 = "Q"
            If singlenum1 = "2" Then offloop1 = "W"
            If singlenum1 = "3" Then offloop1 = "E"
            If singlenum1 = "4" Then offloop1 = "R"
            If singlenum1 = "5" Then offloop1 = "T"
            If singlenum1 = "6" Then offloop1 = "Y"
            If singlenum1 = "7" Then offloop1 = "U"
            If singlenum1 = "8" Then offloop1 = "I"
            SerialPort1.Write(offloop1)
        Next
        Dim loopnum2 As String
        loopnum2 = TxtLoop2.Text
        Dim ListOfloop2 As String() = loopnum2.Split(New Char() {""})
        Dim singlenum2 As String
        Dim offloop2 As String
        offloop2 = "Q"
        For Each singlenum2 In ListOfloop2
            SerialPort1.Write(singlenum2)
            Timer2.Interval = (cmbSPLoop.Value) * 12
            If singlenum2 = "1" Then offloop2 = "Q"
            If singlenum2 = "2" Then offloop2 = "W"
            If singlenum2 = "3" Then offloop2 = "E"
            If singlenum2 = "4" Then offloop2 = "R"
            If singlenum2 = "5" Then offloop2 = "T"
            If singlenum2 = "6" Then offloop2 = "Y"
            If singlenum2 = "7" Then offloop2 = "U"
            If singlenum2 = "8" Then offloop2 = "I"
            SerialPort1.Write(offloop2)
        Next
Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
        OutputToSerialPort()
    End Sub


Private Sub OutputToSerialPort()
    Dim txt = New TextBox
    For index As Integer = 1 To 8
        txt = FindControl(GroupBox1.Controls, "TextBox" & index)
        Dim ListOfloop As Char() = txt.Text.ToCharArray()  '<- edits on this line
        Dim singlenum As String
        Dim offloop As String
        offloop = "Q"
        For Each singlenum In ListOfloop
            'SerialPort1.Write(singlenum)
            'Timer2.Interval = (cmbSPLoop.Value) * 12
            If singlenum = "1" Then offloop = "Q"
            If singlenum = "2" Then offloop = "W"
            If singlenum = "3" Then offloop = "E"
            If singlenum = "4" Then offloop = "R"
            If singlenum = "5" Then offloop = "T"
            If singlenum = "6" Then offloop = "Y"
            If singlenum = "7" Then offloop = "U"
            If singlenum = "8" Then offloop = "I"
            'SerialPort1.Write(offloop)
        Next
    Next index
End Sub

Public Function FindControl(ByVal oControls As Control.ControlCollection,
ByVal strControlName As String) As Control
    Dim MyCtl As Control

    For Each MyCtl In oControls
        If MyCtl.Name = strControlName Then
            Return MyCtl
        Else
            If MyCtl.Controls.Count > 0 Then
                Return FindControl(MyCtl.Controls, strControlName)
            End If
        End If
    Next
    Return Nothing
End Function