当前位置:编程学习 > VB >>

救命啊!VB程序,一个比较复杂的问题,希望集思广益,在线等!!!



这个问题比较复杂,写得比较长,请大家原谅。因为对于VB不是很懂,但是又要实现这个情况,对于我来说实在很难。也因为不知道到底应该用哪些命令来实现,所以我只能把我要得到的结果写出来,希望高手们能给我点意见。

上图的四个方块,被视为四个互相连接的Modul,每个Modul都有四个Dock,分别为0,1,2,3.每个Modul只能够认识与之直接相连的Modul,.首先我要形成这四个Modul的一个Routing Table.正如上图所示。起点-> 终点 [Step]<进口>
第一行的-1表示Modul本身,例如从M1到M1,Step为0.
第二行是因为每个Modul可以认识与自己直接连接的Modul,所以也没有规则。例如,从M1到M0,step为1,从M0的dock2进入M0,所以简写为<M0.2>。
第三行起就有了一定的规则。例如红线标示的部分,因为知道M0与M1相连,于是在M1中寻找与M1直接相连的Modul,得到M2,那么从M0进入M2就需要2Step,因为还是通过M1,所以进口还是M1的Dock0,即为M1.0。同样的规则,可以得到这一行其余的语句。
根据以上的规则,可以通过第三行的信息来完成第四行的语句,直到把整张表格完成。

目前我的程序只能实现第一行,第二行以后的没有办法实现。



第二张图片显示的是我程序目前运行后所得到的结果。首先左边的框里点击那些小方格,形成需要的Modul的不同的组合,被点到的方格标志为“X”,然后点击"Create",给每个Modul赋值。右键点击任意一个Modul,在ListBox中出现这个Modul的完整的Routing。

希望大家帮帮忙。
--------------------编程问答-------------------- 以下是我的程序,希望大家给点意见!!

Public Class Form1

    Structure SMapElement
        Public Dock0 As Integer  'left
        Public Dock1 As Integer  'up
        Public Dock2 As Integer  'right
        Public Dock3 As Integer  'down

        Public ReadOnly Property GetFMS(ByVal iDock As Integer) As Integer
            Get
                Select Case iDock
                    Case 0
                        Return Dock0
                    Case 1
                        Return Dock1
                    Case 2
                        Return Dock2
                    Case 3
                        Return Dock3
                End Select
            End Get
        End Property

        Public ReadOnly Property GetDock(ByVal iFMS As Integer) As Integer
            Get
                If Dock0 = iFMS Then Return 0
                If Dock1 = iFMS Then Return 1
                If Dock2 = iFMS Then Return 2
                If Dock3 = iFMS Then Return 3
                Return -1
            End Get
        End Property
    End Structure

    Private m_Map As Array
    Private m_ListFMS As New ArrayList

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        FlexGrid()
        showFMSInfo(-1)
    End Sub

#Region "FMS Objects"
    Private Sub CreateFMSobjects()

        Dim SID As Integer
        Dim ZID As Integer
        Dim KT As Integer
        Dim DK As Integer

        Dim oFMS As FMS

        For SID = 0 To m_Map.GetLength(0) - 1
            ZID = SID
            KT = 0
            DK = -1
            oFMS = New FMS(SID, ZID, KT, DK)

            m_ListFMS.Add(oFMS)

            AddHandler oFMS.OutputDock, AddressOf OnOutputDock

        Next


    End Sub

    Public Sub OnOutputDock(ByVal iFMS_ID As Integer, ByVal iDock As Integer, ByVal token As SToken)

        Dim iDestFMS, iDestDock As Integer

        iDestFMS = CType(m_Map.GetValue(iFMS_ID), SMapElement).GetFMS(iDock)

        If iDestFMS = -1 Then
        Else
            iDestDock = CType(m_Map.GetValue(iDestFMS), SMapElement).GetDock(iFMS_ID)
        End If

    End Sub
#End Region

#Region "Create"

    Private Sub CreateMap()
        Dim iRow, iCol As Integer
        Dim i As Integer = 0

        For iCol = 0 To AxMSFlexGrid1.Cols - 1
            For iRow = 0 To AxMSFlexGrid1.Rows - 1
                If AxMSFlexGrid1.get_TextMatrix(iRow, iCol) <> "" And i < 100 Then
                    AxMSFlexGrid1.set_TextMatrix(iRow, iCol, i)
                    i += 1
                    If i = 100 Then
                        MessageBox.Show("Es darf nur 99 Module." & Chr(13) & "Bitte das Profil neu erstellen!", "Fehler")
                    End If
                End If
            Next
        Next

        m_Map = Array.CreateInstance(GetType(SMapElement), i)

        For iCol = 0 To AxMSFlexGrid1.Cols - 1
            For iRow = 0 To AxMSFlexGrid1.Rows - 1
                If Not AxMSFlexGrid1.get_TextMatrix(iRow, iCol) = "" Then
                    CreateMapEntry(iRow, iCol)
                End If
            Next
        Next

    End Sub

    Private Sub CreateMapEntry(ByVal iRow As Integer, ByVal icol As Integer)

        If Not AxMSFlexGrid1.get_TextMatrix(iRow, icol) = "" Then

            Dim MapElem As New SMapElement
            MapElem.Dock0 = -1
            MapElem.Dock1 = -1
            MapElem.Dock2 = -1
            MapElem.Dock3 = -1

            Dim i As Integer

            'check Dock0   (links)
            i = iRow - 1
            If i >= 0 Then
                If Not AxMSFlexGrid1.get_TextMatrix(i, icol) = "" Then
                    MapElem.Dock1 = AxMSFlexGrid1.get_TextMatrix(i, icol)
                End If
            End If

            'check Dock1   (oben)
            i = iRow - 1
            If i >= 0 Then
                If Not AxMSFlexGrid1.get_TextMatrix(i, icol) = "" Then
                    MapElem.Dock1 = AxMSFlexGrid1.get_TextMatrix(i, icol)
                End If
            End If

            'check Dock2   (rechts)
            i = icol + 1
            If i < AxMSFlexGrid1.Cols Then
                If Not AxMSFlexGrid1.get_TextMatrix(iRow, i) = "" Then
                    MapElem.Dock2 = AxMSFlexGrid1.get_TextMatrix(iRow, i)
                End If
            End If

            'check Dock3   (unten)
            i = iRow + 1
            If i < AxMSFlexGrid1.Rows Then
                If Not AxMSFlexGrid1.get_TextMatrix(i, icol) = "" Then
                    MapElem.Dock3 = AxMSFlexGrid1.get_TextMatrix(i, icol)
                End If
            End If

            m_Map.SetValue(MapElem, CInt(AxMSFlexGrid1.get_TextMatrix(iRow, icol)))

        End If

    End Sub

#End Region

#Region "FlexGrid"

    Private Sub FlexGrid()
        Dim i As Integer
        Dim iCellSize As Integer = 300

        For i = 0 To AxMSFlexGrid1.Cols - 1
            AxMSFlexGrid1.set_ColWidth(i, iCellSize)
        Next
        For i = 0 To AxMSFlexGrid1.Rows - 1
            AxMSFlexGrid1.set_RowHeight(i, iCellSize)
        Next
    End Sub

    Private Sub AxMSFlexGrid1_MouseDownEvent(ByVal sender As Object, ByVal e As AxMSFlexGridLib.DMSFlexGridEvents_MouseDownEvent) Handles AxMSFlexGrid1.MouseDownEvent

        If e.button = 1 Then
            Dim iCol As Integer = CType(sender, AxMSFlexGridLib.AxMSFlexGrid).MouseCol
            Dim iRow As Integer = CType(sender, AxMSFlexGridLib.AxMSFlexGrid).MouseRow
            If AxMSFlexGrid1.get_TextMatrix(iRow, iCol) = "" Then
                AxMSFlexGrid1.set_TextMatrix(iRow, iCol, "X")
                AxMSFlexGrid1.CellBackColor = Color.Yellow
            Else
                AxMSFlexGrid1.set_TextMatrix(iRow, iCol, "")
                AxMSFlexGrid1.CellBackColor = Color.White
            End If
        End If

        If e.button = 2 Then
            Dim iCol As Integer = CType(sender, AxMSFlexGridLib.AxMSFlexGrid).MouseCol
            Dim iRow As Integer = CType(sender, AxMSFlexGridLib.AxMSFlexGrid).MouseRow
            Dim str As String = AxMSFlexGrid1.get_TextMatrix(iRow, iCol)
            Dim i As Integer

            If str = "X" Or str = "" Then
                i = -1
            Else
                i = CInt(str)
            End If

            showFMSInfo(i)

        End If
    End Sub

#End Region

#Region "Show"
    Public Sub showFMSInfo(ByVal iFMS_ID As Integer)
        ShowDockInfo(iFMS_ID)
        ShowRoutingTable(iFMS_ID)
    End Sub

    Private Sub ShowDockInfo(ByVal iFMS_ID As Integer)
        If iFMS_ID = -1 Then
            Me.Button_FMS.Text = "No FMS"
        Else
            Me.Button_FMS.Text = "FMS " + CStr(iFMS_ID)
        End If
    End Sub

    Private Sub ShowRoutingTable(ByVal iFMS_ID As Integer)

        Me.ListBox_RT.Items.Clear()

        Dim rt As ArrayList
        Dim i As Integer
        Dim str As String

        If Not iFMS_ID = -1 Then

            rt = CType(Me.m_ListFMS.Item(iFMS_ID), FMS).GetRoutingTable()
            For i = 0 To rt.Count - 1
                str = CStr(i) + " : " + CType(rt.Item(i), SToken).str
                Me.ListBox_RT.Items.Add(str)
            Next
        End If


    End Sub
#End Region

#Region "Debugging"


    Private Sub Button_Create_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button_Create.Click
        CreateMap()
        CreateFMSobjects()

    End Sub

    Private Sub Button_Clear_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button_Clear.Click

        AxMSFlexGrid1.Clear()
        Me.Button_FMS.Text = "FMS"
        Me.ListBox_RT.Items.Clear()
        Me.m_ListFMS.Clear()
    End Sub

#End Region


End Class --------------------编程问答-------------------- 一下是FMS.vb

Public Structure SToken
    Public StartID As String
    Public ZielID As String
    Public Kosten As Integer
    Public Dock As Integer

    Public ReadOnly Property str() As String
        Get
            Return StartID + " -> " + ZielID + " [" + CStr(Kosten) + "] via < " + CStr(Dock) + " >"
        End Get
    End Property
End Structure

Public Structure SRT_Entry
    Public Modul As String
    Public Dock As Integer
    Public Kosten As Integer

    Public ReadOnly Property str() As String
        Get
            Return "M: " + Modul + " -- D: " + CStr(Dock) + " -- K: " + CStr(Kosten)
        End Get
    End Property
End Structure

Public Structure SZK
    Public StartID As String
    Public ZielID As String
    Public Kosten As Integer

    Public ReadOnly Property str() As String
        Get
            Return "< " + StartID + " > < " + ZielID + " > < " + CStr(Kosten) + ">"
        End Get
    End Property
End Structure

Public Class FMS
    Private m_ListRT As New ArrayList
    Private m_StartID As Integer
    Private m_ZielID As Integer
    Private m_Kosten As Integer
    Private m_Dock As Integer
    Private m_iMRA As New Integer

    Public Sub New(ByVal SID As Integer, ByVal ZID As Integer, ByVal KT As Integer, ByVal DK As Integer)

        MyBase.New()

        Dim rtEntry As SToken

        rtEntry.StartID = SID
        rtEntry.ZielID = ZID
        rtEntry.Kosten = KT
        rtEntry.Dock = DK

        m_ListRT.Add(rtEntry)

        m_iMRA = -1
        m_StartID = SID
        m_ZielID = ZID
        m_Kosten = KT
        m_Dock = DK

    End Sub

#Region "Simulations-Funktion"
    Public Event OutputDock(ByVal iFMS_ID As Integer, ByVal iDock As Integer, ByVal token As SToken)

    Public Sub inputport(ByVal iPort As Integer, ByVal token As SToken)
        ' token.ZielID =

    End Sub
    Private Sub SendToken(ByVal dock0 As Boolean, ByVal dock1 As Boolean, ByVal dock2 As Boolean, ByVal dock3 As Boolean, ByVal token As SToken)
        If dock0 Then RaiseEvent OutputDock(m_StartID, 0, token)
        If dock1 Then RaiseEvent OutputDock(m_StartID, 1, token)
        If dock2 Then RaiseEvent OutputDock(m_StartID, 2, token)
        If dock3 Then RaiseEvent OutputDock(m_StartID, 3, token)
    End Sub

#End Region

#Region "Debug"
    Public Function GetRoutingTable() As ArrayList
        Return Me.m_ListRT
    End Function
#End Region

End Class --------------------编程问答-------------------- 个人觉得,你先把你所要做的功能说出来,比如你要用在什么地方,做什么用的,或许大家可以从其他方面想到方案来帮你实现,你现在说的这个确实难懂
补充:VB ,  控件
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,