📄 form2.vb
字号:
b1 = totalTime \ interval
a1 = totalTime Mod interval
count = 0
flag = -1
For i = 1 To b1
For j = 1 To interval / 3 * 2
If flag = 1 Then
state = "green"
Else
state = "red"
End If
myTW3.WriteElementString("no" & count, state)
count = count + 1
Next j
For j = interval / 3 * 2 To interval
If flag = 1 Then
state = "yellow"
Else
state = "red"
End If
myTW3.WriteElementString("no" & count, state)
count = count + 1
Next j
flag = -1 * flag
Next i
If a1 > interval Then
For i = 1 To interval
myTW3.WriteElementString("no" & count, "red")
count = count + 1
Next
For i = 1 To (a1 - interval) / 3 * 2
myTW3.WriteElementString("no" & count, "green")
count = count + 1
Next
For i = (a1 - interval) / 3 * 2 To (a1 - interval)
myTW3.WriteElementString("no" & count, "green")
count = count + 1
Next
Else
For i = 1 To a1
myTW3.WriteElementString("no" & count, "red")
count = count + 1
Next i
End If
myTW3.WriteEndElement()
myTW3.WriteEndDocument()
myTW3.Close()
'----红绿灯组f5,f8
myTW4.WriteStartDocument()
myTW4.Formatting = Formatting.Indented
myTW4.WriteStartElement("group")
b1 = totalTime \ interval
a1 = totalTime Mod interval
count = 0
flag = 1
For i = 1 To b1
For j = 1 To interval / 3 * 2
If flag = 1 Then
state = "green"
Else
state = "red"
End If
myTW4.WriteElementString("no" & count, state)
count = count + 1
Next j
For j = interval / 3 * 2 To interval
If flag = 1 Then
state = "yellow"
Else
state = "red"
End If
myTW4.WriteElementString("no" & count, state)
count = count + 1
Next j
flag = -1 * flag
Next i
If a1 > interval Then
For i = 1 To interval / 3 * 2
myTW4.WriteElementString("no" & count, "green")
count = count + 1
Next
For i = interval / 3 * 2 To interval
myTW4.WriteElementString("no" & count, "yellow")
count = count + 1
Next
For i = 1 To a1 - interval
myTW4.WriteElementString("no" & count, "red")
count = count + 1
Next
Else
For i = 1 To a1 / 3 * 2
myTW4.WriteElementString("no" & count, "green")
count = count + 1
Next i
For i = a1 / 3 * 2 To a1
myTW4.WriteElementString("no" & count, "yellow")
count = count + 1
Next i
End If
myTW4.WriteEndElement()
myTW4.WriteEndDocument()
myTW4.Close()
'----红绿灯组f3,f4
myTW5.WriteStartDocument()
myTW5.Formatting = Formatting.Indented
myTW5.WriteStartElement("group")
b1 = totalTime \ interval
a1 = totalTime Mod interval
count = 0
flag = -1
For i = 1 To b1
For j = 1 To interval / 3 * 2
If flag = 1 Then
state = "green"
Else
state = "red"
End If
myTW5.WriteElementString("no" & count, state)
count = count + 1
Next j
For j = interval / 3 * 2 To interval
If flag = 1 Then
state = "yellow"
Else
state = "red"
End If
myTW5.WriteElementString("no" & count, state)
count = count + 1
Next j
flag = -1 * flag
Next i
If a1 > interval Then
For i = 1 To interval
myTW5.WriteElementString("no" & count, "red")
count = count + 1
Next
For i = 1 To (a1 - interval) / 3 * 2
myTW5.WriteElementString("no" & count, "green")
count = count + 1
Next
For i = (a1 - interval) / 3 * 2 To (a1 - interval)
myTW5.WriteElementString("no" & count, "yellow")
count = count + 1
Next
Else
For i = 1 To a1
myTW5.WriteElementString("no" & count, "red")
count = count + 1
Next i
End If
myTW5.WriteEndElement()
myTW5.WriteEndDocument()
myTW5.Close()
'--判断计算车辆等待时间
'---读取XML内容
Dim doc As New XmlDocument
doc.Load(Application.StartupPath & "\carInfor.xml")
Dim doc2 As New XmlDocument
doc2.Load(Application.StartupPath & "\lightInfor.xml")
Dim doc3 As New XmlDocument
doc3.Load(Application.StartupPath & "\lightInfor2.xml")
Dim doc4 As New XmlDocument
doc4.Load(Application.StartupPath & "\lightInfor3.xml")
Dim doc5 As New XmlDocument
doc5.Load(Application.StartupPath & "\lightInfor4.xml")
Dim waitingtime As Integer
count = 1
For j = 0 To 5
Select Case (j + 1)
Case 1
For i = 1 To totalTime \ arrival(j)
waittime = 0
Dim child As XmlNode = doc.SelectSingleNode("/group/CarNo." & count & "/turn")
Dim node As XmlNode = doc.SelectSingleNode("/group/CarNo." & count & "/arrival")
' Dim nr As New XmlNodeReader(child)
a = child.InnerText
b = node.InnerText
Dim child2 As XmlNode = doc2.SelectSingleNode("/group/no" & b)
If a = 1 Then
If child2.InnerText = "red" Then
waittime = b Mod interval
waitingtime = waitingtime + b Mod interval
End If
End If
count = count + 1
Next i
Debug.WriteLine(waitingtime)
Case 2
For i = 1 To totalTime \ arrival(j)
waittime = 0
Dim child3 As XmlNode = doc.SelectSingleNode("/group/CarNo." & count & "/turn")
Dim turn3 As XmlNode = doc.SelectSingleNode("/group/CarNo." & count & "/turn2")
Dim node3 As XmlNode = doc.SelectSingleNode("/group/CarNo." & count & "/arrival")
' Dim nr As New XmlNodeReader(child)
a = child3.InnerText
b = node3.InnerText
c = turn3.InnerText
Dim child4 As XmlNode = doc2.SelectSingleNode("/group/no" & b)
If a = 1 Then
If child4.InnerText = "red" Then
waitingtime = waitingtime + b Mod interval
waittime = b Mod interval
End If
End If
If c = 1 Then
b = b + waittime + L / speed(7)
If b < totalTime Then
Dim turn4 As XmlNode = doc4.SelectSingleNode("/group/no" & b)
If turn4.InnerText = "red" Then
waitingtime = waitingtime + b Mod interval
End If
End If
End If
count = count + 1
Next i
Debug.WriteLine(waitingtime)
Case 3
For i = 1 To totalTime \ arrival(j)
waittime = 0
Dim child5 As XmlNode = doc.SelectSingleNode("/group/CarNo." & count & "/turn")
Dim node5 As XmlNode = doc.SelectSingleNode("/group/CarNo." & count & "/arrival")
' Dim nr As New XmlNodeReader(child)
a = child5.InnerText
b = node5.InnerText
Dim child6 As XmlNode = doc5.SelectSingleNode("/group/no" & b)
If a = 1 Then
If child6.InnerText = "red" Then
waitingtime = waitingtime + b Mod interval
waittime = b Mod interval
End If
End If
count = count + 1
Next i
Debug.WriteLine(waitingtime)
Case 4
For i = 1 To totalTime \ arrival(j)
waittime = 0
Dim child7 As XmlNode = doc.SelectSingleNode("/group/CarNo." & count & "/turn")
Dim turn5 As XmlNode = doc.SelectSingleNode("/group/CarNo." & count & "/turn2")
Dim node7 As XmlNode = doc.SelectSingleNode("/group/CarNo." & count & "/arrival")
' Dim nr As New XmlNodeReader(child)
a = child7.InnerText
b = node7.InnerText
c = turn5.InnerText
Dim child8 As XmlNode = doc5.SelectSingleNode("/group/no" & b)
If a = 1 Then
If child8.InnerText = "red" Then
waitingtime = waitingtime + b Mod interval
waittime = b Mod interval
End If
End If
If c = 1 Then
b = b + waittime + L / speed(6)
If b < totalTime Then
Dim turn6 As XmlNode = doc3.SelectSingleNode("/group/no" & b)
If turn6.InnerText = "red" Then
waitingtime = waitingtime + b Mod interval
End If
End If
End If
count = count + 1
Next i
Debug.WriteLine(waitingtime)
Case 5
For i = 1 To totalTime \ arrival(j)
waittime = 0
Dim child9 As XmlNode = doc.SelectSingleNode("/group/CarNo." & count & "/turn")
Dim node9 As XmlNode = doc.SelectSingleNode("/group/CarNo." & count & "/arrival")
Dim turn9 As XmlNode = doc.SelectSingleNode("/group/CarNo." & count & "/arrival")
' Dim nr As New XmlNodeReader(child)
a = child9.InnerText
b = node9.InnerText
c = turn9.InnerText
Dim child10 As XmlNode = doc4.SelectSingleNode("/group/no" & b)
If a = 1 Then
If child10.InnerText = "red" Then
waitingtime = waitingtime + b Mod interval
waittime = b Mod interval
End If
End If
If c = 1 Then
b = b + waittime + L / speed(6)
If b < totalTime Then
Dim turn10 As XmlNode = doc3.SelectSingleNode("/group/no" & b)
If turn10.InnerText = "red" Then
waitingtime = waitingtime + b Mod interval
End If
End If
End If
count = count + 1
Next i
Debug.WriteLine(waitingtime)
Case 6
For i = 1 To totalTime \ arrival(j)
waittime = 0
Dim child11 As XmlNode = doc.SelectSingleNode("/group/CarNo." & count & "/turn")
Dim node11 As XmlNode = doc.SelectSingleNode("/group/CarNo." & count & "/arrival")
Dim turn7 As XmlNode = doc.SelectSingleNode("/group/CarNo." & count & "/turn2")
' Dim nr As New XmlNodeReader(child)
a = child11.InnerText
b = node11.InnerText
c = turn7.InnerText
Dim child12 As XmlNode = doc3.SelectSingleNode("/group/no" & b)
If a = 1 Then
If child12.InnerText = "red" Then
waitingtime = waitingtime + b Mod interval
waittime = b Mod interval
End If
End If
If c = 1 Then
b = b + waittime + L / speed(7)
If b < totalTime Then
Dim turn8 As XmlNode = doc4.SelectSingleNode("/group/no" & b)
If turn8.InnerText = "red" Then
waitingtime = waitingtime + b Mod interval
End If
End If
End If
count = count + 1
Next i
Debug.WriteLine(waitingtime)
End Select
Next j
'---输出部分
TextBox2.Text = waitingtime / carNumber
End Sub
Private Sub Button2_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
End
End Sub
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
'--构造并调用aboutus窗体
Dim frmabout As New aboutus
frmabout.Show()
End Sub
Private Sub PictureBox2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PictureBox2.Click
MsgBox("我们是S.u.p.e.rHD工作小组~^________^")
End Sub
End Class
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -