Results 1 to 16 of 16

Thread: code conversion from vb.net to vb6.0

  1. #1

    Thread Starter
    Member
    Join Date
    Nov 2012
    Posts
    58

    code conversion from vb.net to vb6.0

    Can someone convert the following code from vb.net to vb6.0 please?

    Code:
    Dim settings As New XmlWriterSettings()
    settings.Indent = True
    settings.Encoding = System.Text.Encoding.UTF8
    
    Dim writer As XmlWriter = XmlWriter.Create("example.xml", settings)
    
    writer.WriteStartDocument()
    writer.WriteStartElement("Continent")
    writer.WriteStartElement("EUROPE")
    writer.WriteStartAttribute("Country")
    writer.WriteValue("UK")
    writer.WriteEndAttribute()
    writer.WriteEndElement()
    writer.WriteStartElement("ASIA")
    writer.WriteStartAttribute("Country")
    writer.WriteValue("Chine")
    writer.WriteEndAttribute()
    writer.WriteEndElement()
    writer.WriteEndDocument()
    writer.close()
    Last edited by dday9; Dec 3rd, 2021 at 03:24 PM.

  2. #2
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: code conversion from vb.net to vb6.0

    XmlWriter is specific to .Net, and there is no VB6 equivalent that I am aware of (bear in mind that VB6 is older than XML).

    You would need to re-write the code entirely, so it is best to ask in the VB6 forum

  3. #3
    Super Moderator dday9's Avatar
    Join Date
    Mar 2011
    Posts
    12,371

    Re: code conversion from vb.net to vb6.0

    Moderator Actions: Moved to VB6 forum.
    "Code is like humor. When you have to explain it, it is bad." - Cory House
    VbLessons | HtmlLessons | CssLessons | Code Tags | Sword of Fury - Jameram

  4. #4
    Super Moderator dday9's Avatar
    Join Date
    Mar 2011
    Posts
    12,371

    Re: code conversion from vb.net to vb6.0

    I'm not a VB6 programmer, but your desired output is to create an XML file with the following document:
    HTML Code:
    <?xml version="1.0" encoding="utf-8"?>
    <Continent>
      <EUROPE Country="UK" />
      <ASIA Country="Chine" />
    </Continent>
    I'm sure in VB6 you can create a text file from a raw String, something like:
    Code:
    Dim xml As String = "<?xml version=""1.0"" encoding=""utf-8"">" & vbNewLine & "<Continent>" & vbNewLine & "  <EUROPE Country=""UK"" />" & vbNewLine & "  <ASIA Country=""Chine"" />" & vbNewLine & "</Continent>"
    ' however VB6 creates a text file from a String, maybe something like (pseudo code)
    Dim fso As New FileSystemObject
    fso.CreateTextFile "example.xml"
    
    Set textStream = fso.OpenTextFile("example.xml", ForWriting, True)
    textStream.Write xml
    textStream.Close
    Edit - By the way, I know you're looking for a VB6 solution, but here is a suggestion for your .NET code:
    Code:
    Dim continent As XElement = <Continent>
                                    <EUROPE Country="UK"/>
                                    <ASIA Country="Chine"/>
                                </Continent>
    Dim document As New XDocument(New XDeclaration("1.0", "UTF-8", "yes"), continent)
    IO.File.WriteAllText("exmaple.xml", document.ToString())
    Last edited by dday9; Dec 6th, 2021 at 11:29 AM.
    "Code is like humor. When you have to explain it, it is bad." - Cory House
    VbLessons | HtmlLessons | CssLessons | Code Tags | Sword of Fury - Jameram

  5. #5
    PowerPoster
    Join Date
    Jun 2013
    Posts
    7,454

    Re: code conversion from vb.net to vb6.0

    .NET:
    Code:
    Dim settings As New XmlWriterSettings()
    settings.Indent = True
    settings.Encoding = System.Text.Encoding.UTF8
    
    Dim writer As XmlWriter = XmlWriter.Create("example.xml", settings)
    
    writer.WriteStartDocument()
    writer.WriteStartElement("Continent")
    writer.WriteStartElement("EUROPE")
    writer.WriteStartAttribute("Country")
    writer.WriteValue("UK")
    writer.WriteEndAttribute()
    writer.WriteEndElement()
    writer.WriteStartElement("ASIA")
    writer.WriteStartAttribute("Country")
    writer.WriteValue("Chine")
    writer.WriteEndAttribute()
    writer.WriteEndElement()
    writer.WriteEndDocument()
    writer.close()
    VB6:
    Code:
    With New_c.StringBuilder 
        .AddNL "<?xml version='1.0' encoding='utf-8'?>"
        .AddNL "<Continent>"
        .Add "  <EUROPE": .AppendXMLAttribute "Country", "UK": .AddNL "/>"
        .Add "  <ASIA":   .AppendXMLAttribute "Country", "Chine": .AddNL "/>"
        .AddNL "</Continent>"
        New_c.FSO.WriteByteContent App.Path & "\some.xml", .ToUTF8
    End With
    Olaf
    Last edited by Shaggy Hiker; Dec 6th, 2021 at 10:32 AM. Reason: Removed a quote from a post that was also removed.

  6. #6
    PowerPoster PlausiblyDamp's Avatar
    Join Date
    Dec 2016
    Location
    Pontypool, Wales
    Posts
    2,958

    Re: code conversion from vb.net to vb6.0

    Quote Originally Posted by Schmidt View Post
    ???

    .NET:
    Code:
    Dim settings As New XmlWriterSettings()
    settings.Indent = True
    settings.Encoding = System.Text.Encoding.UTF8
    
    Dim writer As XmlWriter = XmlWriter.Create("example.xml", settings)
    
    writer.WriteStartDocument()
    writer.WriteStartElement("Continent")
    writer.WriteStartElement("EUROPE")
    writer.WriteStartAttribute("Country")
    writer.WriteValue("UK")
    writer.WriteEndAttribute()
    writer.WriteEndElement()
    writer.WriteStartElement("ASIA")
    writer.WriteStartAttribute("Country")
    writer.WriteValue("Chine")
    writer.WriteEndAttribute()
    writer.WriteEndElement()
    writer.WriteEndDocument()
    writer.close()
    VB6:
    Code:
    With New_c.StringBuilder 
        .AddNL "<?xml version='1.0' encoding='utf-8'?>"
        .AddNL "<Continent>"
        .Add "  <EUROPE": .AppendXMLAttribute "Country", "UK": .AddNL "/>"
        .Add "  <ASIA":   .AppendXMLAttribute "Country", "Chine": .AddNL "/>"
        .AddNL "</Continent>"
        New_c.FSO.WriteByteContent App.Path & "\some.xml", .ToUTF8
    End With
    Olaf
    Or actual VB.Net code, complete with intellisense while typing the XML in the IDE...
    Code:
    Dim doc = <Continent>
                        <Europe Country="UK"/>
                        <Asia Country="China"/>
                    </Continent>
    doc.Save("example.xml")

  7. #7
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    40,102

    Re: code conversion from vb.net to vb6.0

    There was some interesting, potentially valuable, discussion going on, but it was way off the original post, and getting back to the old fight that everybody is so familiar with. Therefore, in the hopes that the OP can actually get a useful answer without it being lost in the fight, I removed all the discussion.
    My usual boring signature: Nothing

  8. #8
    PowerPoster
    Join Date
    Jun 2013
    Posts
    7,454

    Re: code conversion from vb.net to vb6.0

    Quote Originally Posted by Shaggy Hiker View Post
    I removed all the discussion.
    Yeah, along with the recommendations towards the OP, to use "JSON instead"
    (including the VB6-example I've posted for that).

    It's kinda sad, what's happening in recent threads here.

    .NETers who feel that they are using "superior stuff" (not knowing "all the other tools") -
    and a few VB6-hobbyists, who complain about any "technical discurs" that makes them "feel uncomfortable".

    Perhaps introducing a SubForum, called "Safe-Space" (like the thing at certain US-Universities),
    would be a good idea where all the more "snowflaky inclined" developers can "talk about things without any emotional disturbances".

    In such a SubForum only "utter politeness and happiness will rule"...
    Once there, you could make statements like:
    1 + 1 = 3

    And everyone would outright encourage you with sentences like:
    "Basically right, keep going..."
    or
    "Looks good to me... Off-By-One mistakes are common in development..."

    Olaf

  9. #9
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    40,102

    Re: code conversion from vb.net to vb6.0

    Quote Originally Posted by Schmidt View Post
    Yeah, along with the recommendations towards the OP, to use "JSON instead"
    (including the VB6-example I've posted for that).

    It's kinda sad, what's happening in recent threads here.

    .NETers who feel that they are using "superior stuff" (not knowing "all the other tools") -
    and a few VB6-hobbyists, who complain about any "technical discurs" that makes them "feel uncomfortable".

    Perhaps introducing a SubForum, called "Safe-Space" (like the thing at certain US-Universities),
    would be a good idea where all the more "snowflaky inclined" developers can "talk about things without any emotional disturbances".

    In such a SubForum only "utter politeness and happiness will rule"...
    Once there, you could make statements like:
    1 + 1 = 3

    And everyone would outright encourage you with sentences like:
    "Basically right, keep going..."
    or
    "Looks good to me... Off-By-One mistakes are common in development..."

    Olaf
    I felt the JSON stuff was potentially useful, but also not at all on topic. The OP was asking about converting some XML code. If people don't want to use XML that's fine, but it still exists, still has to be worked with, and the OP was asking about that. Therefore, since the JSON conversation, while useful, was not on topic and was embedded in a conversation that was very much off topic, away it went. I could split it out into a different thread, if you felt it was a topic for further exploration, or you could start a thread on it.

    As for the rest: Find this kind of arguing in other forums on this site. You'll find it in Chit-Chat (cause you'll find anything there), you can find it in General Developer (but still just VB6 stuff), and that's it. You'd think that there would be some VB vs C# stuff, since that's also a contentious division, but it doesn't exist. A comment here, a comment there, and nobody takes the bait so the argument is over before it starts.
    My usual boring signature: Nothing

  10. #10
    PowerPoster yereverluvinuncleber's Avatar
    Join Date
    Feb 2014
    Location
    Norfolk UK (inbred)
    Posts
    3,560

    Re: code conversion from vb.net to vb6.0

    Those C# barstewards... its time we took a trip over there and gave them some the medicine we get here.

    Who's with me? Let's go get us a possee! (said in my most American accent).
    https://github.com/yereverluvinunclebert

    Skillset: VMS,DOS,Windows Sysadmin from 1985, fault-tolerance, VaxCluster, Alpha,Sparc. DCL,QB,VBDOS- VB6,.NET, PHP,NODE.JS, Graphic Design, Project Manager, CMS, Quad Electronics. classic cars & m'bikes. Artist in water & oils. Historian.

    By the power invested in me, all the threads I start are battle free zones - no arguing about the benefits of VB6 over .NET here please. Happiness must reign.

  11. #11
    PowerPoster dilettante's Avatar
    Join Date
    Feb 2006
    Posts
    24,487

    Re: code conversion from vb.net to vb6.0

    I'm not sure what there was to argue about. We have a SAX Writer we can use in VB6 just fine:

    Code:
    Option Explicit
    '
    'Requires references to:
    '
    '   o Microsoft ActiveX Data Objects 2.5 Library (or later)
    '   o Microsoft XML, v6.0 (can also be used with v3.0)
    '
    
    Private Sub Main()
        Dim Stream As ADODB.Stream
        Dim Writer As MSXML2.MXXMLWriter60
        Dim Content As MSXML2.IVBSAXContentHandler
        Dim ContinentAttrs As MSXML2.SAXAttributes60
    
        Set Stream = New ADODB.Stream
        With Stream
            .Open
            .Type = adTypeBinary
        End With
        Set Writer = New MSXML2.MXXMLWriter60
        With Writer
            .output = Stream
            .omitXMLDeclaration = False
            .encoding = "utf-8"
            .standalone = True
            .indent = True
        End With
        Set Content = Writer
        Set ContinentAttrs = New MSXML2.SAXAttributes60
        'We'll define attribute 0 as "Country" and assign its value as we use the collection:
        ContinentAttrs.addAttribute "", "", "Country", "", ""
        With Content
            .startDocument
            .startElement "", "", "Continent", Nothing
            ContinentAttrs.setValue 0, "UK"
            .startElement "", "", "EUROPE", ContinentAttrs
            .endElement "", "", "EUROPE"
            ContinentAttrs.setValue 0, "Chine"
            .startElement "", "", "ASIA", ContinentAttrs
            .endElement "", "", "ASIA"
            .endElement "", "", "Continent"
            .endDocument
        End With
        Writer.flush
        On Error Resume Next
        Kill "example.xml"
        On Error GoTo 0
        With Stream
            .SaveToFile "example.xml"
            .Close
        End With
    End Sub

  12. #12
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    40,102

    Re: code conversion from vb.net to vb6.0

    Quote Originally Posted by yereverluvinuncleber View Post
    Those C# barstewards... its time we took a trip over there and gave them some the medicine we get here.

    Who's with me? Let's go get us a possee! (said in my most American accent).
    You don't need a posse. There aren't enough of them for you to need any help.
    My usual boring signature: Nothing

  13. #13
    PowerPoster Elroy's Avatar
    Join Date
    Jun 2014
    Location
    Near Nashville TN
    Posts
    10,909

    Re: code conversion from vb.net to vb6.0

    Quote Originally Posted by dilettante View Post
    I'm not sure what there was to argue about. We have a SAX Writer we can use in VB6 just fine:
    Thank you, Dil. I was going to make a similar comment, but wasn't going to jump in while there was so much noise.

    And yeah, we have XML reading/writing options that work just fine!
    Any software I post in these forums written by me is provided "AS IS" without warranty of any kind, expressed or implied, and permission is hereby granted, free of charge and without restriction, to any person obtaining a copy. To all, peace and happiness.

  14. #14
    PowerPoster
    Join Date
    Jun 2013
    Posts
    7,454

    Re: code conversion from vb.net to vb6.0

    Quote Originally Posted by dilettante View Post
    I'm not sure what there was to argue about.
    There was no arguing originally.

    In my very first post here, I've included even a solution quite similar to yours (based on the MS-XML-lib).

    Why that first post was removed by Shaggy without any good reason -
    (due to silly complaints from Elroy and others), escapes me.

    What is now sitting in posting-slot #5 was posted much later in the discussion.

    Tssk... <shaking head>

    Olaf

  15. #15
    PowerPoster dilettante's Avatar
    Join Date
    Feb 2006
    Posts
    24,487

    Re: code conversion from vb.net to vb6.0

    You can also assign any object that implements the OLE IStream instead of using an ADO Stream object. For example an IStream opened directly on a file. Or just leave Writer.output as a String (its default) and grab its value at the end. It all depends on what you are doing.

    The .Net stuff probably just wraps thes COM objects. Or perhaps by now that has been replaced by newer code written in C# or .Net IL or something.

  16. #16
    Angel of Code Niya's Avatar
    Join Date
    Nov 2011
    Posts
    9,017

    Re: code conversion from vb.net to vb6.0

    Quote Originally Posted by dilettante View Post
    The .Net stuff probably just wraps thes COM objects.
    I doubt it because I'm pretty sure these XML classes can be used in Linux and Android applications. The COM infrastructure is not supported on these operating systems.
    Treeview with NodeAdded/NodesRemoved events | BlinkLabel control | Calculate Permutations | Object Enums | ComboBox with centered items | .Net Internals article(not mine) | Wizard Control | Understanding Multi-Threading | Simple file compression | Demon Arena

    Copy/move files using Windows Shell | I'm not wanted

    C++ programmers will dismiss you as a cretinous simpleton for your inability to keep track of pointers chained 6 levels deep and Java programmers will pillory you for buying into the evils of Microsoft. Meanwhile C# programmers will get paid just a little bit more than you for writing exactly the same code and VB6 programmers will continue to whitter on about "footprints". - FunkyDexter

    There's just no reason to use garbage like InputBox. - jmcilhinney

    The threads I start are Niya and Olaf free zones. No arguing about the benefits of VB6 over .NET here please. Happiness must reign. - yereverluvinuncleber

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width