Traduction vb6 en vb.net

mohamed222222 Messages postés 161 Date d'inscription mardi 12 juin 2007 Statut Membre Dernière intervention 22 avril 2009 - 9 août 2007 à 16:58
Renfield Messages postés 17287 Date d'inscription mercredi 2 janvier 2002 Statut Modérateur Dernière intervention 27 septembre 2021 - 10 août 2007 à 08:11
Bonjour








Quelqu'un peut me traduire ça en vb.net ?








Const



sFileContent




As String



=



"1;paris;ibis"



& vbNewLine & _

                     
       



"2;marseille;concorde"












Private Sub



Form_Load()




Dim



oXML



As



DOMDocument




Dim



oRoot



As



IXMLDOMElement




Dim



i



As Long










Dim



xsHotels()



As String










Dim



xsParts()



As String






 



'# L'objet qui va nous permettre de manipuler notre document.






 



Set



oXML =



New



DOMDocument

 



'# Racine de notre document






  oXML.appendChild oXML.createElement(



"hotels"



)

 

 



'# On découpe la chaine d'entrée par lignes : une ligne = un hotel






  xsHotels = Split(sFileContent, vbNewLine)

 



For



i =



0




To UBound



(xsHotels)

     



'# On créé un élément 'hotel' pour chaque
hotel






     



Set



oRoot = oXML.createElement(



"hotel"



)

      oXML.childNodes(



0



).appendChild oRoot

     

     



'# On découpe chacun des champs qui compose
chaque ligne






      xsParts = Split(xsHotels(i),



";"



)

     

     



'# On definit chaque attribut






      oRoot.setAttribute



"id"



, xsParts(



0



)

      oRoot.setAttribute



"ville"



, xsParts(



1



)

      oRoot.setAttribute



"nom"



, xsParts(



2



)

 



Next



i

 

 



'# On crée le fichier XML






  oXML.save



"C:\d.xml"










End Sub






[code.aspx?ID=41455




]

3 réponses

Utilisateur anonyme
9 août 2007 à 17:10
Encore ?

Ca doit donner ca (non tester) :




Const sFileContent As String = "1;paris;ibis" & ControlChars.CrLf & "2;marseille;concorde"

Private Sub TaForm_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
  Dim oXML As Xml.XmlDocument
  Dim oRoot As Xml.XmlElement
  Dim xsHotels() As String
  Dim xsParts() As String
  '# L'objet qui va nous permettre de manipuler notre document. 
  oXML = New Xml.XmlDocument()
  '# Racine de notre document 
  oXML.appendChild(oXML.createElement("hotels"))

  '# On découpe la chaine d'entrée par lignes : une ligne = un hotel 
  xsHotels = Split(sFileContent, vbNewLine)
  For i As Integer = 0 To xsHotels.GetUpperBound(0)
      '# On créé un élément 'hotel' pour chaque hotel 
      oRoot = oXML.CreateElement("hotel")
      oXML.ChildNodes(0).AppendChild(oRoot)

      '# On découpe chacun des champs qui compose chaque ligne 
      xsParts = xsHotels(i).Split(";"c)

      '# On definit chaque attribut 
      oRoot.SetAttribute("id", xsParts(0))
      oRoot.SetAttribute("ville", xsParts(1))
      oRoot.SetAttribute("nom", xsParts(2))
  Next i

  '# On crée le fichier XML 
  oXML.save("C:\d.xml")
End Sub,

----

(Nouveau forum VBA/Office
0
Big200148 Messages postés 149 Date d'inscription mardi 30 septembre 2003 Statut Membre Dernière intervention 23 juillet 2009
9 août 2007 à 17:10
Il n'y a rien de bien compliquer pour le traduire. Il faut juste changer la gestion du XML
0
Renfield Messages postés 17287 Date d'inscription mercredi 2 janvier 2002 Statut Modérateur Dernière intervention 27 septembre 2021 74
10 août 2007 à 08:11
le DOM reste le DOM, une fois dans l'espace de noms System.Xml....

Renfield
Admin CodeS-SourceS- MVP Visual Basic
0
Rejoignez-nous