S
Silverado
Hi Leute ich hoffe das ihr mir helfen könnt ich habe gehört das INI Fils unter VB.Net out sind. XML soll jetzt der Nachfolger sein. Hier hab ich ein etwas aber ich weiß nicht wie ich das jetzt anwenden soll wen ich ein toll form habe und ich etwas eingebe z.B. eine Zahl und die soll dann gespeichert werden.
ich habe disen code in ein modul eingefügt.
Code:
Private Sub CreateSettings(ByVal Path As String)
Dim xml As New XmlDocument()
Dim node As XmlElement
xml.AppendChild(xml.CreateXmlDeclaration("1.0", "UTF-8", "yes"))
xml.AppendChild(xml.CreateElement("Settings"))
xml.Save(Path)
End Sub
Private Function GetXMLElementByTagName(ByVal Parent As XmlNode, ByVal Tag As String) As XmlNode()
Dim ret() As XmlNode = {}
Dim i As Integer
With Parent
For i = 0 To .ChildNodes.Count - 1
If .ChildNodes(i).Name = Tag Then
ReDim ret(0)
ret(0) = .ChildNodes(i)
Return ret
End If
Next
Return ret
End With
End Function
Public Sub setSetting(ByVal Path As String, ByVal Head As String, ByVal Key As String, ByVal Value As String)
Dim xml As New XmlDocument()
If Not File.Exists(Path) Then CreateSettings(Path) : Application.DoEvents()
xml.Load(Path)
With xml.ChildNodes(1)
Dim thead As XmlElement
If GetXMLElementByTagName(xml.ChildNodes(1), Head).Length = 0 Then thead = xml.CreateElement(Head) Else thead = CType(GetXMLElementByTagName(xml.ChildNodes(1), Head)(0), XmlElement)
Dim tsub As XmlElement
If GetXMLElementByTagName(thead, Key).Length = 0 Then tsub = xml.CreateElement(Key) Else tsub = CType(GetXMLElementByTagName(thead, Key)(0), XmlElement)
tsub.InnerText = Value
thead.AppendChild(tsub)
.AppendChild(thead)
End With
xml.Save(Path)
End Sub
Public Function getSetting(ByVal Path As String, ByVal Head As String, ByVal Key As String) As String
If Not File.Exists(Path) Then Return ""
Dim xml As New XmlDocument()
xml.Load(Path)
With xml.ChildNodes(1)
If GetXMLElementByTagName(xml.ChildNodes(1), Head).Length > 0 Then
Dim thead As XmlNode = GetXMLElementByTagName(xml.ChildNodes(1), Head)(0)
If GetXMLElementByTagName(thead, Key).Length > 0 Then
Return GetXMLElementByTagName(thead, Key)(0).InnerText
End If
End If
End With
Return ""
End Function
ich habe disen code in ein modul eingefügt.