拆分字符串然后将其传递给函数

时间:2013-10-25 23:09:22

标签: .net vb.net winforms

我有以下代码:

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

    If Not TextBox1.Text = "" Then
        If TextBox1.Text.Contains("ping") Then
            Dim PingSplit = TextBox1.Text.Split(" ")
        End If

        Select Case TextBox1.Text

            Case "ping"
                MsgBox(PingSplit(2).ToString)' debug
                '  If Not Regex.Match(PingSplit(2), "\A(\d{1,2}/(1[0-99]\d)/(2[0-55]\d)).(\d{1,2}/(1[0-99]\d)/(2[0-55]\d)).(\d{1,2}/(1[0-99]\d)/(2[0-55]\d)).(\d{1,2}/(1[0-99]\d)/(2[0-55]\d))\Z").Success Then
                MsgBox("Invalid address!")
                Else
                MsgBox(GetPingMs(PingSplit(2)))
                End If
        End Select

    Else
        MsgBox("System: Please insert a command!")
    End If
End Sub

但是我无法弄清楚如何让代码在textbox1中拆分文本并将下半部分传递给GetPingMs函数,我知道函数有效,我只是无法弄清楚如何传递数据。任何帮助将不胜感激。

1 个答案:

答案 0 :(得分:0)

您的PingSplitIf内宣布,Select无法使用。

此外,我不明白您尝试在TextBox1.Text中选择哪种情况

在所有if之前移动'PingSplit'的声明,但仍然在该函数内:

Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        Dim PingSplit as String
If Not TextBox1.Text = "" Then
        If TextBox1.Text.Contains("ping") Then
            PingSplit = TextBox1.Text.Split(" ")
        End If

        Select Case TextBox1.Text

            Case "ping"
                MsgBox(PingSplit(1).ToString)' debug

                ' Commented if by question author.
                '  If Not Regex.Match(PingSplit(1), "\A(\d{1,2}/(1[0-99]\d)/(2[0-55]\d)).(\d{1,2}/(1[0-99]\d)/(2[0-55]\d)).(\d{1,2}/(1[0-99]\d)/(2[0-55]\d)).(\d{1,2}/(1[0-99]\d)/(2[0-55]\d))\Z").Success Then
                'MsgBox("Invalid address!")
                'Else
                'MsgBox(GetPingMs(PingSplit(1)))
                'End If
        End Select

    Else
        MsgBox("System: Please insert a command!")
    End If
End Sub