While xChar <> EOF
xChar = xChar + 1
SelChar = Left((Right(RichTextbox1.Text,xChar),1)
If IsNumeric(SelChar) Then
Case Select "1" ...
End Select
End If
Loop Until EOF
That's semi-psuedo-code, but is that the kind of thing you want?
Please remember to rate posts! Rate any post you find helpful. Use the link to the left - "Rate this Post". Please use [highlight='vb'] your code goes in here [/highlight] tags when posting code. When a question you asked has been resolved, please go to the top of the original post and click "Thread Tools" then select "Mark Thread Resolved."
you can do this with clever use of the Split() function, theres no need for extra componants, I havent vb6 here so I can't give you the code but just a suggestion
Where do you get the control? I downloaded MSXML 4.0 SP2 Parser and SDK(msxml.msi) off microsoft and I cant find the control anywhere.
theres no out of the ordinary control involved with the code above (that had just 2 richtextboxes on a form), i didnt say you'll add a component to the project for msxml... add the reference to msxml 4... click project (between view and format) in the ide menu then click references.
Last edited by leinad31; Nov 18th, 2006 at 01:39 PM.
Ok I think I'm confused Here is my project file. I want it so when you click my button at the bottem it takes the text from the top one and adds it to the second one in the way I said in Post #1. I used both code together was I only suposed to used 1? Also does anyone know about the split function?
If Not arr1(i) = arr2(i) Then arr1(i) = arr1(i) & vbNewLine & arr2(i)
Next
str1 = join(arr1, vbNewLine)
Debug.Print str1
returns
<Hi>
1
once
<by>
2
twice
</by>
</Hi>
i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case. Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next
dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part
come back and mark your original post as resolved if your problem is fixed
pete
Your confused about adding a reference? Here the project with the reference added... if it errors out on load then that means you don't have MSXML 4 in your references list.
Split works but you will pass up the chance to learn to use MSXML objects if you go that way.
I had the refence and you code worked just fine but I don't want the the text to appear in a dialog as it does. This is how I have my coder layed out. I have two forms. One is the main form and two is the secondary. I want it so when you press a command button in form2(Secondary) it takes the text from the richtextbox in form2
<Hi>
whatevers here
<by>
whatevers here
</by>
</Hi>
and does what your example does but adds the text to the existing richtextbox's text in form1..... Can this be done?
I was just trying to apply that code the way I wanted and found out something that poses a problem for my app As long as its text in the spot above called "whatevers here" it works fine Etc. Hi, By,........
But if you use something like this <building> and then </Bulding> inbetween in just gives you whats typed in rtb1 in a message box. Does anyone know how to fix this?
have a look at the sample i posted, it should do what you want, just replace str1 and str2 with your rich textboxes
i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case. Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next
dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part
come back and mark your original post as resolved if your problem is fixed
pete
There are only three steps in that algorithm, loading the data, recursion, and display. So you will obviously update code after the recursion. Change the MsgBox or Debug.Print Line to
rtbA.Text = xmlDocA.xml
EDIT westconn, this is xml, a line can contain several tags such as
<Hi>
1
<by>
2
</by></Hi>
... your algo assumes they are formatted similarly per line and fails if not similarly formatted even if the tags are ordered/nested properly...
Last edited by leinad31; Nov 19th, 2006 at 05:13 PM.
@leinad31: Ya your code works perfect until you add something like <House> or </House> or anything with a < or a > between <Hi> and <by> or between <by> and </by> in either one of the xml soarce file and then it doesn't work and just displays whats in the first soarce file. Do you know how to fix this?
@westconn1: I used your code in the example below to demostrate the kind of thing I want. The problem is the I want anything in between to show up and not just put that code in. Maybe I didn't apply it right, check it out
Post what's the possible complete structure, or note the optional tags... the previous algorithm updated source A with B elements on the assumption that A and B have the same structure (by in hi and no other elements)... if the structure is variable, eg for <Hi> elements to be combined either A or B have additional tags such as <building> then we have to include additional processing to ensure that only Hi and By are combined.
I'll look into it later when I get home, I'm at a rental so there's no VB here.
And I need representative copies of the source xmls... does the zip above contain those? or does the project retrieve them from an online site? Otherwise the posts above are my only reference for the xml structure.
Ok... this makes a collection of the <Hi> elements then uses XPath, on value passed to selectsinglenode method's argument, to get the <by> child by element of each <Hi> element. I mentioned those in case you want to do additional research related to the code below.
Loop While (cntHi < ndsHiA.length - 1 Or cntHi < ndsHiB.length - 1)
Form1.RichTextBox1.Text = xmlDocA.xml 'or output to textfile with print statement
End Sub
Please note that only the text node of the <Hi> and <by> elements are merged... the richtextbox final output is the updated xml for source A, hence uses the xml structure of A... if there were child nodes in source B, such as <buildings>, they are left in source B and not transffered/merged with source A.
And lastly, your last project assigned the same xml (richtextbox.text) to xmlDocA and xmlDocB objects.
Last edited by leinad31; Nov 21st, 2006 at 04:35 AM.
O wait know I know what your saying The problem is I dont want to load the xml files I want it so you type it into the form2 richtextbox and then add it to the current code the method I said above. How do you make this code work in this fashion?
I didn't put error handling cause I thought you would be passing valid xml's
<1>... tag name is erroneous... so you will have to rename that
text() node does not exist in childnodes if there's no text... just test if ndA Or ndB is Nothing
VB Code:
'blah blah lines
Set ndA = ndsHiA.Item(cntHi).selectSingleNode("text()")
Set ndB = ndsHiB.Item(cntHi).selectSingleNode("text()")
If Not (ndA Is Nothing) And Not (ndB Is Nothing) Then
Did you remove/replace the invalid xml tags <1> and <2>? If the xml is invaliud then of course it won't be loaded into the domdocument. Try this instead
I used that so its valid and all it did was take my form1 richtextbox and reorganize it like so.
Code:
<Hi>
<a1>
</a1>
<by>
<b2>
</b2>
</by>
</Hi>
when it was like this
Code:
<Hi>
<a1>
</a1>
<by>
<b2>
</b2>
</by>
</Hi>
I doesn't add my code form2 richtextbox though.
Maybe my code is invalid for the form2 richtextbox. Can you post some xml code that will splice in my program with the one you just posted ?
Please note that only the text node of the <Hi> and <by> elements are merged... the richtextbox final output is the updated xml for source A, hence uses the xml structure of A... if there were child nodes in source B, such as <buildings>, they are left in source B and not transffered/merged with source A.
So what are you really trying to accomplish? We've been beating around the bush and making samples for cases which appear to be related to what you need but is not exactly what you needed.
I want it so from <gauge> to <mouse> all the text from the other form gets added inbetween its <gauge> to <mouse> and also between <mouse> and </mouse>.
Sorry, what I meant is I typed the first section of code into form1 richtextbox and the second to form2 richtextbox and pressed the "add code" command button in form2 and it gave be the error. I'v changed Hi to Gauge and by to Mouse ??? Any ideas?
seems the xml object automatically indents the elements to show the nesting... similar to what happens when you view the xml source in a browser... using Replace() to remove the vbTab indents returns a non-indented source if that's what you want.