Quantcast
Channel: VBForums - Visual Basic 6 and Earlier
Viewing all articles
Browse latest Browse all 21156

[RESOLVED] Problem with UDT

$
0
0
Hi,

I have got a little problem with UDT.
At the beginning I've to say i dont get any errors, its just not working the way it should.

The Main idea is, i want to save a UDT in another UDT and this in an array. I m using it to search through a XML-Document.

My two UDTs are

Code:

Public Type PDISZone

        Name As String
        Count As Integer

        Parameter(2) As Double
        DelaytimePh As Double
        DelaytimeGnd As Double
        Reversed As String
        KFactor As Double

End Type



Public Type PDIS

        ModuleName As String
        Zones(10) As PDISZone

End Type

and this is the part where i call the UDT.(Import part is highlighted)

Code:

' ************************************************************
' This is module *Module6 .
' Automatically generated uses comments are placed here.
' Don't edit these lines.
' {BEGINUSES}
'#Uses "*Module1"
'#Uses "*Module2"
'#Uses "*Module3"
'#Uses "*Module4"
'#Uses "*Module5"
'#Uses "*Module6"
'#Uses "*Module7"
' {ENDUSES}
' ************************************************************
'-->function for parsing and searching through XML Documents

Public Function xXMLR(FilePath As String) As Variant()

        On Error GoTo ErrorHandler


        Set objParser = CreateObject("Microsoft.XMLDOM")

        Dim xDoc As MSXML2.DOMDocument
    Dim ObjTmpArray(400) As Variant
    Dim ExitTemplate As NameTemplate
    Dim NameTemplate As NameTemplate

    Dim Manufacturer As MSXML2.IXMLDOMElement

    'initialize ObjTempArray
        ExitTemplate.ModuleName = "End"
    For j=0 To 400

                ObjTmpArray(j) = ExitTemplate
    Next

        Dim NodeListLN As IXMLDOMNodeList
        Dim NodeLN As MSXML2.IXMLDOMElement

        Dim PrimaryCurrent As Double
        Dim SecondaryCurrent As Double
        Dim        TransRatio As Double

        Dim OCC As String
        Dim i As Integer

        Dim PTOC As PTOC
        Dim tPTOC(5) As String

        Dim PDIS As PDIS
        Dim PDISZone As PDISZone
        Dim tPDISZoneParameter(2) As Double
        Dim tPDISZones(10) As PDISZone
        Dim PDISFound As Boolean

        PDISFound = False

        OCC = "OMICRON Control Center"
        i = 0
        j = 0

        Set xDoc = New MSXML2.DOMDocument

        '-->Prooves whether the document is a valid XML Document.
        xDoc.validateOnParse = True

        '-->DTD = Document Type Definition

        If xDoc.load(FilePath) = False Then

                MsgBox ("Unable to load File.",vbExclamation,OCC)
        Else

                MsgBox("File: " & FilePath &  vbNewLine & "succesfully loaded!",vbInformation,OCC)

                '-->Siemens Relais

                Set Manufacturer = xDoc.documentElement.selectSingleNode("//IED[@manufacturer]")

                '-->Reading the *.cid file



                Set NodeListLN = xDoc.documentElement.selectNodes("//LDevice/LN")

                If Manufacturer.getAttribute("manufacturer")= "SIEMENS" Then

                        NameTemplate.ModuleName = "Siemens-Relais: " & Manufacturer.getAttribute("type")
                        ObjTmpArray(400) = NameTemplate


                        '-->Transmition Ratio
                        PrimCt = CDbl(xDoc.selectSingleNode("//LN[@desc='CT 3-phase']/DOI[@name='ARtgINsens']/SDI[@name='setMag']").lastChild.Text)
                        SecCt = CDbl(xDoc.selectSingleNode("//LN[@desc='CT 3-phase']/DOI[@name='ARtgSecINs']/SDI[@name='setMag']").lastChild.Text)
                ElseIf Manufacturer.getAttribute("manufacturer")= "ABB" Then

                        NameTemplate.ModuleName = "ABB-Relais: " & Manufacturer.getAttribute("type")
                        ObjTmpArray(400) = NameTemplate


                        PrimCt = CDbl(xDoc.selectSingleNode("//LN[@desc='Current (Io,CT)']/DOI[@name='ARtg']/SDI[@name='setMag']").lastChild.Text)
                        '-->Replace, because ABB saves value and unity in the same Node
                        SecCt = CDbl(Replace(xDoc.selectSingleNode("//LN[@desc='Current (Io,CT)']/DOI[@name='ARtgSec']/DAI[@name='setVal']").lastChild.Text,"A",""))
                End If

                '-->Transmition Ratio
                TransRatio = PrimCt/SecCt

                '-->just for testing

                MsgBox(CStr(ObjTmpArray(400).ModuleName) & vbNewLine & "Transmition Ratio: " & CStr(TransRatio),OCC)

                For Each NodeLN In NodeListLN

                        '-->Siemens Relais

                        If Manufacturer.getAttribute("manufacturer")= "SIEMENS" Then

                                '-->Find all PTOC-Zones in the SCL File
                                If NodeLN.getAttribute("lnClass") = "PTOC" Then

                                        PTOC.Threshold = CDbl(NodeLN.selectSingleNode("DOI[@name='StrVal']/SDI[@name='setMag']").lastChild.Text)/TransRatio
                                        PTOC.Modus = NodeLN.selectSingleNode("DOI[@name='Mode']").lastChild.Text
                                        PTOC.Delay = CDbl(NodeLN.selectSingleNode("DOI[@name='OpDlTmms']/DAI[@name='setVal']").lastChild.Text)/1000
                                        PTOC.DropOutRate = CDbl(NodeLN.selectSingleNode("DOI[@name='DrpoutRat']/SDI[@name='setMag']").lastChild.Text)

                                        Set NodeLNParent = NodeLN.parentNode

                                        PTOC.desc = NodeLNParent.getAttribute("inst")
                                        PTOC.Zone = NodeLN.getAttribute("inst")

                                        PTOC.ModuleName = "PTOC"


                                        ObjTmpArray(i)=PTOC
                                        i=i+1

                                ElseIf NodeLN.getAttribute("lnClass") = "PDIS" Then

                                        PDISFound = True


                                        PDISZone.Name = NodeLN.getAttribute("desc")
                                        PDISZone.Count = NodeLN.getAttribute("inst")

                                        '-->Zone Parameters: 0: X Reach 1: R (ph-g) 2: R (ph-ph)
                                        tPDISZoneParameter(0)=CDbl(NodeLN.selectSingleNode("DOI[@name='X1']/SDI[@name='setMag']").lastChild.Text)
                                        tPDISZoneParameter(1)=CDbl(NodeLN.selectSingleNode("DOI[@name='RisGndRch']/SDI[@name='setMag']").lastChild.Text)
                                        tPDISZoneParameter(2)=CDbl(NodeLN.selectSingleNode("DOI[@name='RisPhRch']/SDI[@name='setMag']").lastChild.Text)

                                        PDISZone.Parameter = tPDISZoneParameter
                                        PDISZone.Reversed = NodeLN.selectSingleNode("DOI[@name='DirMod']").lastChild.Text
                                        PDISZone.DelaytimePh = CDbl(NodeLN.selectSingleNode("DOI[@name='PhDlTmms']/DAI[@name='setVal']").lastChild.Text)
                                        PDISZone.DelaytimeGnd = CDbl(NodeLN.selectSingleNode("DOI[@name='GndDlTmms']/DAI[@name='setVal']").lastChild.Text)
                                        PDISZone.KFactor = CDbl(NodeLN.selectSingleNode("DOI[@name='K0Fact']/SDI[@name='setMag']").lastChild.Text)

                                        tPDISZones(j) = PDISZone
                                        j=j+1

                                Else
                                        If PDISFound = True Then

                                                PDIS.ModuleName = "PDIS"
                                                PDIS.Zones = tPDISZones
                                                ObjTmpArray(i)=PDIS

                                                Dim test(10) As PDISZone

                                                test = PDIS.Zones

                                                debug.print(CStr(test(i).KFactor))

                                                i=i+1
                                                j=0



                                                PDISFound = False
                                        End If
                                End If


                                '-->ABB Relais

                        ElseIf Manufacturer.getAttribute("manufacturer")= "ABB" Then



                                If NodeLN.getAttribute("lnClass") = "PTOC" Then

                                        PTOC.Threshold = CDbl(NodeLN.selectSingleNode("DOI[@name='StrVal']/SDI[@name='setMag']").lastChild.Text)*SecCt
                                        PTOC.Delay = CDbl(NodeLN.selectSingleNode("DOI[@name='OpDlTmms']/DAI[@name='setVal']").lastChild.Text)/1000




                                        'Curve Parameters
                                        tPTOC(0) = NodeLN.selectSingleNode("DOI[@name='TmACrv']/DAI[@name='setCharact']").lastChild.Text
                                        tPTOC(1) = NodeLN.selectSingleNode("DOI[@name='TmACrv']/DAI[@name='setParA']").lastChild.Text
                                        tPTOC(2) = NodeLN.selectSingleNode("DOI[@name='TmACrv']/DAI[@name='setParB']").lastChild.Text
                                        tPTOC(3) = NodeLN.selectSingleNode("DOI[@name='TmACrv']/DAI[@name='setParC']").lastChild.Text
                                        tPTOC(4) = NodeLN.selectSingleNode("DOI[@name='TmACrv']/DAI[@name='setParD']").lastChild.Text
                                        tPTOC(5) = NodeLN.selectSingleNode("DOI[@name='TmACrv']/DAI[@name='setParE']").lastChild.Text

                                        PTOC.Curve = tmpArray
                                        PTOC.desc = NodeLN.getAttribute("lnType")
                                        PTOC.Zone = NodeLN.getAttribute("inst")

                                        PTOC.ModuleName = "PTOC"

                                        ObjTmpArray(i)=PTOC

                                        i=i+1

                                End If
                        End If
                Next
        End If


        xXMLR = ObjTmpArray

        '-->Clear all Lists
        Set NodeListLN = Nothing
        Set NodeListDOI = Nothing
        Set NodeListSDI = Nothing
        Set xDoc = Nothing

        ErrorHandler:
                Resume Next

End Function

The problem is when i test it, it always return me 0. It should be 1 due to the XML document.

EDIT: i also tried Debug.Print(CStr(tPDISZones(0).KFactor)) and it returns 1 as it should so the error has to be in the highlighted red section. (the part of the if then else order is reached, so its no mistake of choosing the conditions )

Best regards

Sascha

EDIT2: I managed to solve the Problem myself. :-)

Viewing all articles
Browse latest Browse all 21156

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>