How to parse XML using vba

前端 未结 8 1180
不思量自难忘°
不思量自难忘° 2020-11-22 08:46

I work in VBA, and want to parse a string eg



        
8条回答
  •  故里飘歌
    2020-11-22 09:30

    Here is a short sub to parse a MicroStation Triforma XML file that contains data for structural steel shapes.

    'location of triforma structural files
    'c:\programdata\bentley\workspace\triforma\tf_imperial\data\us.xml
    
    Sub ReadTriformaImperialData()
    Dim txtFileName As String
    Dim txtFileLine As String
    Dim txtFileNumber As Long
    
    Dim Shape As String
    Shape = "w12x40"
    
    txtFileNumber = FreeFile
    txtFileName = "c:\programdata\bentley\workspace\triforma\tf_imperial\data\us.xml"
    
    Open txtFileName For Input As #txtFileNumber
    
    Do While Not EOF(txtFileNumber)
    Line Input #txtFileNumber, txtFileLine
        If InStr(1, UCase(txtFileLine), UCase(Shape)) Then
            P1 = InStr(1, UCase(txtFileLine), "D=")
            D = Val(Mid(txtFileLine, P1 + 3))
    
            P2 = InStr(1, UCase(txtFileLine), "TW=")
            TW = Val(Mid(txtFileLine, P2 + 4))
    
            P3 = InStr(1, UCase(txtFileLine), "WIDTH=")
            W = Val(Mid(txtFileLine, P3 + 7))
    
            P4 = InStr(1, UCase(txtFileLine), "TF=")
            TF = Val(Mid(txtFileLine, P4 + 4))
    
            Close txtFileNumber
            Exit Do
        End If
    Loop
    End Sub
    

    From here you can use the values to draw the shape in MicroStation 2d or do it in 3d and extrude it to a solid.

提交回复
热议问题