koddump:enhanceindexentries
Differences
This shows you the differences between two versions of the page.
Next revision | Previous revision | ||
koddump:enhanceindexentries [2008/03/11 16:41] – created 192.176.230.1 | koddump:enhanceindexentries [2011/11/24 20:47] (current) – old revision restored jetthe | ||
---|---|---|---|
Line 1: | Line 1: | ||
+ | **Funktionskrav: | ||
+ | |||
+ | Ändra indexmarkeringar på formen: | ||
+ | **{ XE "EN 789" | ||
+ | till: | ||
+ | **{ XE "EN 789; | ||
+ | |||
+ | Dvs lägga till ett sorteringsvärde för varje indexmarkering och padda ut det till fyra siffror. | ||
+ | |||
+ | |||
+ | |||
+ | Dagens ickeoptade funktion: | ||
+ | |||
<code vb> | <code vb> | ||
Sub EnhanceIndexEntries() | Sub EnhanceIndexEntries() | ||
Line 42: | Line 55: | ||
End Sub | End Sub | ||
</ | </ | ||
+ | |||
+ | Exempel på paddingfunktion, | ||
+ | <code javascript> | ||
+ | function padNumber(number, | ||
+ | number = new Number(number); | ||
+ | size = parseInt(size); | ||
+ | if(isNaN(size) || isNaN(number)) return number+""; | ||
+ | if(number < Math.pow(10, | ||
+ | number+=Math.pow(10, | ||
+ | return (number+"" | ||
+ | }else{ | ||
+ | return number+""; | ||
+ | } | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | |||
+ | Halvoptad kod, går ~dubbelt så snabbt som den ooptade: | ||
+ | <code vb> | ||
+ | Sub NewEnhanceIndexEntries() | ||
+ | Dim doc As Document | ||
+ | Dim fld As Field | ||
+ | Dim temp As String | ||
+ | Dim temp2 As String | ||
+ | Dim omsg As String | ||
+ | Dim matches As MatchCollection | ||
+ | Dim re3 As RegExp | ||
+ | Set re3 = New RegExp | ||
+ | re3.Global = False | ||
+ | re3.Pattern = " | ||
+ | Dim match As match | ||
+ | Dim mval As String | ||
+ | |||
+ | Dim cnt As Integer | ||
+ | cnt = 0 | ||
+ | | ||
+ | Set doc = ActiveDocument | ||
+ | For Each fld In doc.Fields | ||
+ | fld.Select | ||
+ | If fld.Type = wdFieldIndexEntry Then | ||
+ | cnt = cnt + 1 | ||
+ | temp = fld.Code | ||
+ | If (re3.Test(temp) = True) Then | ||
+ | Set matches = re3.Execute(temp) | ||
+ | For Each match In matches | ||
+ | mval = match.Value | ||
+ | Next | ||
+ | | ||
+ | Dim size As Integer | ||
+ | mval = Mid(mval, 2) | ||
+ | mval = Left(mval, Len(mval) - 1) | ||
+ | size = 4 | ||
+ | If (Len(mval) < (size + 1)) Then | ||
+ | Do While (Len(mval) < size) | ||
+ | mval = " | ||
+ | Loop | ||
+ | End If | ||
+ | | ||
+ | temp2 = Left(temp, Len(temp) - 1) | ||
+ | temp2 = temp2 & ";" | ||
+ | With Selection.Find | ||
+ | .Text = temp | ||
+ | .Replacement.Text = temp2 | ||
+ | .Forward = True | ||
+ | .Wrap = wdFindStop | ||
+ | .Format = False | ||
+ | .Execute Replace: | ||
+ | End With | ||
+ | Else | ||
+ | ' NOOP | ||
+ | End If | ||
+ | End If | ||
+ | Next | ||
+ | Set fld = Nothing | ||
+ | Set doc = Nothing | ||
+ | omsg = " | ||
+ | MsgBox (omsg & cnt) | ||
+ | End Sub | ||
+ | </ | ||
+ | |||
koddump/enhanceindexentries.1205250070.txt.gz · Last modified: 2008/03/11 16:41 by 192.176.230.1