Thema Datum  Von Nutzer Rating
Antwort
17.02.2015 11:11:21 Simon
NotSolved
Blau Textdatei einlesen
17.02.2015 13:45:37 Gast60298
NotSolved
17.02.2015 13:47:49 Gast19651
Solved
17.02.2015 14:27:48 Gast81213
NotSolved
17.02.2015 14:56:15 Gast96112
NotSolved
18.02.2015 09:28:57 Gast66852
NotSolved
18.02.2015 11:35:16 Gast62343
NotSolved
18.02.2015 13:49:52 Gast74787
NotSolved
18.02.2015 16:04:35 Gast2048
NotSolved

Ansicht des Beitrags:
Von:
Gast60298
Datum:
17.02.2015 13:45:37
Views:
963
Rating: Antwort:
  Ja
Thema:
Textdatei einlesen

probier mal:

Option Explicit

Sub Test01()
  
  Dim xmlDoc        As Object 'MSXML2.DOMDocument
  Dim xmlNode       As Object 'MSXML2.IXMLDOMNode
  Dim wksOutput     As Excel.Worksheet
  Dim strValue      As String
  Dim avnt          As Variant
  
  Set wksOutput = Worksheets("Sheet1")
  
'>> loading xml >>
  Set xmlDoc = CreateObject("MSXML2.DOMDocument")
  xmlDoc.async = False
  
  If Not xmlDoc.Load("D:\95810.txt") Then
    MsgBox xmlDoc.parseError.reason
  End If
'<< loading xml <<

'>> SampleRate >>
  Set xmlNode = xmlDoc.SelectSingleNode("./Scope/Settings")
  avnt = Split(xmlNode.FirstChild.NodeValue, vbLf)
'# output
  wksOutput.Range("A1").Value = "SampleRate:"
  If GetKeyValue(avnt, "Timebase Data", "SampleRate", strValue) Then
    wksOutput.Range("B1").Value = strValue
  Else
    wksOutput.Range("B1").Value = ""
  End If
'<< SampleRate <<

'>> Channels X/Y-Data >>
  Set xmlNode = xmlDoc.SelectSingleNode("./Scope/TraceData")
  
  Dim vntXY() As Variant
  Dim j As Long
  Dim i As Long
  
  For i = 0 To xmlNode.ChildNodes.Length - 1
    
    With xmlNode.ChildNodes(i)
      
      ReDim vntXY(0 To Val(.Attributes.getNamedItem("NumElements").NodeValue) - 1, 0 To 1)
      
      For j = LBound(vntXY) To UBound(vntXY)
        With .ChildNodes(j).Attributes
          vntXY(j, 0) = Val(.getNamedItem("X").NodeValue)
          vntXY(j, 1) = Val(.getNamedItem("Y").NodeValue)
        End With
      Next
      
'# output
      wksOutput.Range("A3:B3").Offset(, i * 2).Font.Bold = True
      wksOutput.Range("A3:B3").Offset(, i * 2).Value = Array(.nodeName & " X", .nodeName & " Y")
      wksOutput.Range("A4").Offset(, i * 2).Resize(1 + UBound(vntXY), 2).Value = vntXY
      
    End With
    
    DoEvents
  Next
'<< Channels X/Y-Data <<
  
End Sub

Private Function GetKeyValue(List As Variant, Section As String, Key As String, ByRef KeyValue As String) As Boolean
  
  Dim blnSection As Boolean
  Dim vntElement As Variant
  
  For Each vntElement In List
    
    If Left$(vntElement, 1) = "[" And Right$(vntElement, 1) = "]" Then
      If 0 = StrComp("[" & Section & "]", vntElement, vbTextCompare) Then
        blnSection = True
      Else
        blnSection = False
      End If
    Else
      If blnSection Then
        If 0 = StrComp(Key, Trim$(Left$(vntElement, InStr(1, vntElement, "=") - 1)), vbTextCompare) Then
          KeyValue = Trim$(Right$(vntElement, Len(vntElement) - InStr(1, vntElement, "=")))
          GetKeyValue = True
          Exit Function
        End If
      End If
    End If
    
  Next
  
End Function

 


Ihre Antwort
  • Bitte beschreiben Sie Ihr Problem möglichst ausführlich. (Wichtige Info z.B.: Office Version, Betriebssystem, Wo genau kommen Sie nicht weiter)
  • Bitte helfen Sie ebenfalls wenn Ihnen geholfen werden konnte und markieren Sie Ihre Anfrage als erledigt (Klick auf Häckchen)
  • Bei Crossposting, entsprechende Links auf andere Forenbeiträge beifügen / nachtragen
  • Codeschnipsel am besten über den Code-Button im Text-Editor einfügen
  • Die Angabe der Emailadresse ist freiwillig und wird nur verwendet, um Sie bei Antworten auf Ihren Beitrag zu benachrichtigen
Thema: Name: Email:



  • Bitte beschreiben Sie Ihr Problem möglichst ausführlich. (Wichtige Info z.B.: Office Version, Betriebssystem, Wo genau kommen Sie nicht weiter)
  • Bitte helfen Sie ebenfalls wenn Ihnen geholfen werden konnte und markieren Sie Ihre Anfrage als erledigt (Klick auf Häckchen)
  • Bei Crossposting, entsprechende Links auf andere Forenbeiträge beifügen / nachtragen
  • Codeschnipsel am besten über den Code-Button im Text-Editor einfügen
  • Die Angabe der Emailadresse ist freiwillig und wird nur verwendet, um Sie bei Antworten auf Ihren Beitrag zu benachrichtigen

Thema Datum  Von Nutzer Rating
Antwort
17.02.2015 11:11:21 Simon
NotSolved
Blau Textdatei einlesen
17.02.2015 13:45:37 Gast60298
NotSolved
17.02.2015 13:47:49 Gast19651
Solved
17.02.2015 14:27:48 Gast81213
NotSolved
17.02.2015 14:56:15 Gast96112
NotSolved
18.02.2015 09:28:57 Gast66852
NotSolved
18.02.2015 11:35:16 Gast62343
NotSolved
18.02.2015 13:49:52 Gast74787
NotSolved
18.02.2015 16:04:35 Gast2048
NotSolved