-
No increments
hi all,
My problem is simple.
i hae documents that contains tagged text like this
<UL>
<ITEM NUM = “ “><p>this is a test text</p> </ITEM>
<ITEM NUM = “ “><p>this is a test text</p> </ITEM>
<ITEM NUM = “ “><p>this is a test text</p> </ITEM>
<ITEM NUM = “ “><p>this is a test text</p> </ITEM>
</UL>
<OL>
<ITEM NUM = “ “><p>this is a test text</p> </ITEM>
<ITEM NUM = “ “><p>this is a test text</p> </ITEM>
<ITEM NUM = “ “><p>this is a test text</p> </ITEM>
<ITEM NUM = “ “><p>this is a test text</p> </ITEM>
</OL>
i want <Item Num=" "> to be numbered and the numbering should start afresh for each list. this is the code that i am using
Code:
Sub imain()
Dim atr As Integer
s = id_num("<OL>", "</OL>", "<ITEM NUM = "" "">", "<ITEM NUM = ")
s = id_num("<UL>", "</UL>", "<ITEM NUM = "" "">", "<ITEM NUM = ")
End Sub
Function id_num(stag As String, etag As String, attrib As String, repk As String)
Selection.HomeKey Unit:=wdStory
Selection.Find.ClearFormatting
With Selection.Find
.Text = stag
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Dim i As Integer
Do
If (Selection.Find.Execute) Then
i = 0
Do
i = i + 1
Selection.MoveStart Unit:=wdLine, Count:=1
Selection.MoveEnd Unit:=wdLine, Count:=1
Selection.MoveLeft Unit:=wdCharacter, Count:=1, Extend:=wdExtend
If InStr(1, Selection.Text, etag) Then
Selection.MoveRight Unit:=wdCharacter, Count:=1, Extend:=wdMove
i = 0
Exit Do
Else
Selection.Find.Text = attrib
Selection.Find.Replacement.Text = repk & "" & i & "" & " > """
Selection.Find.Execute Replace:=wdReplaceOne
End If
Loop Until i = 100
Else
Exit Do
i = 0
End If
Loop
End Function
But when i run the macro the output that i get is like this
Code:
<OL>
<ITEM NUM = 1 > “<p>this is a test text</p> </ITEM>
<ITEM NUM = 2 > “<p>this is a test text</p> </ITEM>
<ITEM NUM = 3 > “<p>this is a test text</p> </ITEM>
<ITEM NUM = 4 > “<p>this is a test text</p> </ITEM>
<ITEM NUM = 5 > “<p>this is a test text</p> </ITEM>
<ITEM NUM = 6 > “<p>this is a test text</p> </ITEM>
<ITEM NUM = 7 > “<p>this is a test text</p> </ITEM>
<ITEM NUM = 8 > “<p>this is a test text</p> </ITEM>
<ITEM NUM = 9 > “<p>this is a test text</p> </ITEM>
<ITEM NUM = 10 > “<p>this is a test text</p> </ITEM>
<ITEM NUM = 11 > “<p>this is a test text</p> </ITEM>
</OL>
<UL>
<ITEM NUM = 1 > “<p>this is a test text</p> </ITEM>
<ITEM NUM = 1 > “<p>this is a test text</p> </ITEM>
<ITEM NUM = 2 > “<p>this is a test text</p> </ITEM>
<ITEM NUM = 3 > “<p>this is a test text</p> </ITEM>
<ITEM NUM = 4 > “<p>this is a test text</p> </ITEM>
<ITEM NUM = 5 > “<p>this is a test text</p> </ITEM>
<ITEM NUM = 6 > “<p>this is a test text</p> </ITEM>
<ITEM NUM = 7 > “<p>this is a test text</p> </ITEM>
<ITEM NUM = 8 > “<p>this is a test text</p> </ITEM>
<ITEM NUM = 9 > “<p>this is a test text</p> </ITEM>
<ITEM NUM = 10 > “<p>this is a test text</p> </ITEM>
</UL>
<OL>
<ITEM NUM = 12 > “<p>this is a test text</p> </ITEM>
<ITEM NUM = 13 > “<p>this is a test text</p> </ITEM>
<ITEM NUM = 14 > “<p>this is a test text</p> </ITEM>
<ITEM NUM = 15 > “<p>this is a test text</p> </ITEM>
<ITEM NUM = 16 > “<p>this is a test text</p> </ITEM>
<ITEM NUM = 17 > “<p>this is a test text</p> </ITEM>
<ITEM NUM = 18 > “<p>this is a test text</p> </ITEM>
<ITEM NUM = 19 > “<p>this is a test text</p> </ITEM>
<ITEM NUM = 20 > “<p>this is a test text</p> </ITEM>
<ITEM NUM = 21 > “<p>this is a test text</p> </ITEM>
<ITEM NUM = 22 > “<p>this is a test text</p> </ITEM>
</OL>
How can i make the numbering start from "1" for each list?
-
Re: No increments
String manipulation.
If you are reading from a file using open, close, line input and print... you need a variable that holds the count.
If your line inputted is <ol> or <ul> you need to reset the count to 1
If the line is </ol> or </ul> you ignore, otherwise you add in the number and then increment the count by 1