请帮我找到此代码中的错误。我花了一个多小时寻找它。 这是代码..
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获取字符串。哪个不是我想从中得到的那个。就像我在这里使用的那样。我没有看到什么?
答案 0 :(得分: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
现在可行。