coding puzzle

gelo

Member
Joined
Sep 24, 2007
Messages
13
Programming Experience
1-3
heyo new here,

ive been writing a program to edit a special file that is a text based mesh file. In the program i want to make a special replace feature. ive tried so many times but to no avail...

im useing visual basic express 2005

When i get my prog to search for the substring "material="#"" (# = any number including -1)in multiple strings,

i want the first material="#" its found to be changed to material="0",

and the second material="#" its found to be changed to material="1"

and the third material="#" its found to be changed to material="2" and so on and so forth

all this is done via a button on a separate form. the material="#" is in a richtextbox in the main form

if you can get my gist lol, is it possible to do that? if you thought of any code i would be so greatfull for it. with the help youve supplied this site will be referenced in the help box including the person with the code that works.

THANKS!
 
Last edited:
The solution in post 2 works fine, but I can see another solution too if the data is valid Xml. From the fragment you posted it appears to be but there need to be a single root node and the MESH node need to be closed also, like this:
HTML:
<meshes>
  <HEADER MAGIC="XMF" VERSION="919" />
  <MESH NUMSUBMESH="2">
    <SUBMESH NUMVERTICES="399" NUMFACES="664" NUMLODSTEPS="0" NUMSPRINGS="0" NUMMORPHS="0" NUMTEXCOORDS="1" MATERIAL="123">
      <VERTEX NUMINFLUENCES="1" ID="0">
        <POS>47.2458 -73.3203 1101.75</POS>
        <NORM>0.577543 -0.650535 0.493202</NORM>
        <COLOR>1 1 1</COLOR>
        <TEXCOORD>0.576221 0.13896</TEXCOORD>
        <INFLUENCE ID="22">1</INFLUENCE>
      </VERTEX>
      <FACE VERTEXID="0 1 2" />
    </SUBMESH>
    <SUBMESH NUMVERTICES="399" NUMFACES="664" NUMLODSTEPS="0" NUMSPRINGS="0" NUMMORPHS="0" NUMTEXCOORDS="1" MATERIAL="321">
      <VERTEX NUMINFLUENCES="1" ID="0">
        <POS>47.2458 -73.3203 1101.75</POS>
        <NORM>0.577543 -0.650535 0.493202</NORM>
        <COLOR>1 1 1</COLOR>
        <TEXCOORD>0.576221 0.13896</TEXCOORD>
        <INFLUENCE ID="22">1</INFLUENCE>
      </VERTEX>
      <FACE VERTEXID="0 1 2" />
    </SUBMESH>
  </MESH>
</meshes>
In that case you can use Xml methods to do the replace:
VB.NET:
Sub xmlreplacemesh()
    Dim xmldoc As New Xml.XmlDocument
    xmldoc.Load("meshInput.xml")
    Dim submeshes As Xml.XmlNodeList = xmldoc.SelectNodes("meshes/MESH/SUBMESH")
    For i As Integer = 0 To submeshes.Count - 1
        submeshes(i).Attributes("MATERIAL").Value = i.ToString
    Next
    xmldoc.Save("meshOutput.xml")
End Sub
 
hey thanks ofr the heads up, i was going to use xml but as you stated the reason why not is why i didnt choose that path since the xmf file does not use the xml standard.
 
DUDE YOU ARE A MASTER!!! *bows down to the*

im SO adding you to the thanks list!!!!!

i will be back on this site when i start my course project and i have any probs!

i say thankyou again and again hehe
 
Back
Top