|
-
Dec 3rd, 2021, 01:53 PM
#1
Thread Starter
Member
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.
-
Dec 3rd, 2021, 02:42 PM
#2
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
-
Dec 3rd, 2021, 03:25 PM
#3
Re: code conversion from vb.net to vb6.0
Moderator Actions: Moved to VB6 forum.
-
Dec 3rd, 2021, 03:30 PM
#4
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.
-
Dec 5th, 2021, 02:14 PM
#5
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.
-
Dec 5th, 2021, 02:41 PM
#6
Re: code conversion from vb.net to vb6.0
 Originally Posted by Schmidt
???
.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")
-
Dec 6th, 2021, 10:32 AM
#7
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
 
-
Dec 6th, 2021, 01:20 PM
#8
Re: code conversion from vb.net to vb6.0
 Originally Posted by Shaggy Hiker
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
-
Dec 6th, 2021, 01:54 PM
#9
Re: code conversion from vb.net to vb6.0
 Originally Posted by Schmidt
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
 
-
Dec 6th, 2021, 02:23 PM
#10
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.
-
Dec 6th, 2021, 03:31 PM
#11
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
-
Dec 6th, 2021, 03:46 PM
#12
Re: code conversion from vb.net to vb6.0
 Originally Posted by yereverluvinuncleber
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
 
-
Dec 6th, 2021, 04:09 PM
#13
Re: code conversion from vb.net to vb6.0
 Originally Posted by dilettante
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.
-
Dec 6th, 2021, 07:27 PM
#14
Re: code conversion from vb.net to vb6.0
 Originally Posted by dilettante
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
-
Dec 7th, 2021, 02:20 AM
#15
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.
-
Dec 7th, 2021, 03:54 AM
#16
Re: code conversion from vb.net to vb6.0
 Originally Posted by dilettante
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.
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|