Private Function wordwrap(mystring As String, indent As String)
Dim arrwords() As String, i As Integer, newstr As String, longstr As String
arrwords = Split(mystring)
newstr = indent
For i = 0 To UBound(arrwords)
If Not TextWidth(newstr & arrwords(i)) > 6300 Then
newstr = newstr & arrwords(i) & Space(1)
Else
If longstr = "" Then
longstr = newstr
Else
longstr = longstr & vbNewLine & indent & newstr
End If
newstr = indent & arrwords(i) & Space(1)
End If
Next
If longstr = "" Then
wordwrap = newstr
Else: wordwrap = longstr & vbNewLine & indent & indent & newstr
End If
End Function
Private Sub Command1_Click()
Dim i As Integer, pos As Integer, mytest As String, pos1 As Integer
Dim li As Integer, strfi As String, f1 As Integer, arrfi() As String, pard As Boolean
Dim tlen As Integer, myind As String
f1 = FreeFile
Open "spec.rtf" For Input As f1
strfi = Input(LOF(f1), #f1)
Close f1
pard = False
arrfi = Split(strfi, vbNewLine)
Open "spec.txt" For Output As f1
For i = 0 To UBound(arrfi)
If pard = False Then
If InStr(1, arrfi(i), "\pard") = 0 Then
GoTo notyet
Else: pard = True
End If
End If
If Not i = UBound(arrfi) Then
If Not Left(arrfi(i + 1), 1) = "\" Then
arrfi(i) = arrfi(i) & arrfi(i + 1)
arrfi(i + 1) = ""
End If
End If
pos = InStr(1, arrfi(i), "\li")
If Not pos = 0 Then
pos1 = InStr(pos + 3, arrfi(i), "\") - pos - 3
mytest = Mid(arrfi(i), pos + 3, pos1)
If Left(mytest, 1) = "n" Then
pos = InStr(pos + 1, arrfi(i), "\li")
If Not pos = 0 Then
pos1 = InStr(pos + 3, arrfi(i), "\") - pos - 3
mytest = Mid(arrfi(i), pos + 3, pos1)
End If
End If
li = Val(mytest)
' Debug.Print li, i
End If
mytest = ""
tlen = li / 4 / TextWidth(" ")
myind = Space(tlen)
pos = InStrRev(arrfi(i), "\")
If pos = 0 Then
mytest = arrfi(i)
Else
pos = InStr(pos + 1, arrfi(i), " ")
If pos = 0 Then Stop
pos1 = Len(arrfi(i))
If Not Len(arrfi(i)) = pos Then mytest = Right(arrfi(i), Len(arrfi(i)) - pos)
End If
If mytest = "" Or mytest = "}}" Then mytest = " "
If Left(mytest, 1) = "{" Then mytest = Right(mytest, Len(mytest) - 1)
' If i = 37 Then Stop
mytest = wordwrap(mytest, myind)
notyet:
If Not mytest = "" Then Print #f1, mytest 'mytest = "not yet"
Next
Close f1
Shell "notepad.exe spec.txt"
Stop
Exit Sub