Wednesday, December 16, 2009

XML elementa nolasīšana ar VB palīdzību

Šoreiz savajadzējās uztaisīt funkciju, ar kuras palīdzību varam nolasīt konkrēta XML taga vērtību.

Nu tad te nu viņa arīdzan ir uzcepta:


Private Function RetrieveXML_TagValue(filePath As String, TagElementName As String, Optional ItemIndex As Integer = 0) As String
' Function returns Tag element value from XML file
' If ItemIndex is empty, then function returns first tag element

Dim xmlDoc As Object
Set xmlDoc = CreateObject("microsoft.xmldom")

xmlDoc.async = "false"
xmlDoc.Load (filePath)
TagElementName = UCase(TagElementName)

RetrieveXML_TagValue = xmlDoc.getElementsByTagName("" & TagElementName & "").Item("" & ItemIndex & "").nodeTypedValue

End Function

Tuesday, December 08, 2009

Faila nolasīšana ar Visual Basic palīdzību

Savajadzējās uztaisīt procedūru ar kuru varam nolasīt failu (faila rindas) ar VB palīdzību.
Tad nu šeit kauč kas ir sanācis:

Set FSO = CreateObject("Scripting.FileSystemObject")
Set Myfile = FSO.OpenTextFile(filename, 1)

Do While Myfile.AtEndOfStream <> True
   TextLine = Myfile.ReadLine
   Debug.Print "line : " & TextLine
Loop

Myfile.Close
Set Myfile = Nothing
Set FSO = Nothing