0

请帮我找出这段代码中的错误。我花了一个多小时寻找它。这是代码..

Public Class Form1
Dim incomingip() As String
Dim incomingopt() As String

Private Sub btnloadall_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnloadall.Click
    Timer1.Start()
    rtb.Clear()
End Sub

Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
    ProgressBar1.Increment(5)
    If ProgressBar1.Value = 10 Then
        sPort.Write("get ip" & vbCr)
    End If
    If ProgressBar1.Value = 20 Then
        Call btnip_Click(sender, New System.EventArgs)
    End If
    If ProgressBar1.Value = 30 Then
        rtb.Clear()
    End If
    If ProgressBar1.Value = 40 Then
        sPort.Write("get opt" & vbCr)
    End If
    If ProgressBar1.Value = 50 Then
        Call btnopt_Click(sender, New System.EventArgs)
    End If
    'If ProgressBar1.Value = 40 Then
    '    rtb.Clear()
    'End If

    If ProgressBar1.Value = ProgressBar1.Maximum Then
        Timer1.Stop()
    End If
End Sub

在这里,每次我在 rtb 中写东西时,我总是将其清除,因此变量不会读取出现的第一个变量。

Private Sub btnip_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnip.Click

    incomingip = stringOfRtb.Split(ControlChars.CrLf.ToCharArray) ''vcrlf splitter
    ''ip parameters
    ip = incomingip(2).Split("="c)
    txtIP.Text = ip(1)

    ip = incomingip(3).Split("="c)
    txtMask.Text = ip(1)

    ip = incomingip(5).Split("="c)
    txtHost.Text = ip(1)

    ip = incomingip(4).Split("="c)
    txtDfg.Text = ip(1)

    ip = incomingip(10).Split("="c)
    txtBackupIP.Text = ip(1)

    ip = incomingip(1).Split("="c)
    cboDhcp.Text = ip(1)


End Sub

它现在可以很好地显示从 rtb 到不同文本框的拆分字符串..

Private Sub btnopt_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnopt.Click
    incomingopt = stringOfRtb.Split(ControlChars.CrLf.ToCharArray) ''vcrlf splitter
    opt = incomingopt(0).Split("="c)
    txtJointimer.Text = opt(1)

    opt = incomingopt(1).Split("="c)
    txtReplace.Text = opt(1)

    opt = incomingopt(2).Split("="c)
    txtDeviceID.Text = opt(1)

    opt = incomingopt(3).Split("="c)
    txtPassword.Text = opt(1)

    opt = incomingopt(4).Split("="c)
    txtFormat.Text = opt(1)

    opt = incomingopt(5).Split("="c)
    txtSignal.Text = opt(1)

    opt = incomingopt(6).Split("="c)
    txtAverage.Text = opt(1)
End Sub

这个事件显示相同的字符串!即使我声明了不同的实例,此事件也会从 btnip 获取字符串。这不是我想从中得到的。就像我在这里使用了incomingip。我没有看到什么吗?

4

1 回答 1

1

我已经解决了。看起来

Public stringOfRtb as String = Form1.rtb.text

来自全局类的数据不会覆盖其数据。从这里其他人的评论来看,在使用全局函数完成的函数中声明确实更好。这就是我所做的..

Private Sub btnopt_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnopt.Click
    Dim rtbOpt As String = rtb.Text
    incomingopt = rtbOpt.Split(ControlChars.CrLf.ToCharArray) ''vcrlf splitter
    opt = incomingopt(0).Split("="c)
    txtJointimer.Text = opt(1)

    opt = incomingopt(1).Split("="c)
    txtReplace.Text = opt(1)

    opt = incomingopt(2).Split("="c)
    txtDeviceID.Text = opt(1)

    opt = incomingopt(3).Split("="c)
    txtPassword.Text = opt(1)

    opt = incomingopt(4).Split("="c)
    txtFormat.Text = opt(1)

    opt = incomingopt(5).Split("="c)
    txtSignal.Text = opt(1)

    opt = incomingopt(6).Split("="c)
    txtAverage.Text = opt(1)
End Sub

现在它可以工作了。

于 2013-11-08T07:13:28.883 回答