Results 1 to 7 of 7

Thread: RTF and breaking it up

  1. #1

    Thread Starter
    Hyperactive Member badgers's Avatar
    Join Date
    Sep 1999
    Location
    Madison, WI USA
    Posts
    444
    I have the following Rich text file
    >076<
    CONDUCTOR MATERIAL
    >078<
    COPPER
    Conductors shall be copper (Cu), #10 AWG and smaller may
    be either solid or stranded, #8 AWG and larger shall be
    stranded.

    Final connections to all motors and/or equipment subject
    to vibrations or movement shall be made with stranded
    copper conductors.
    >080<
    ALUMINUM
    Stranded aluminum (Al) conductors may be substituted for
    copper for feeders rated 150 amps and larger, except for
    HVAC and diagnostic equipment (X-Ray, MRI, CT-Scanner,
    etc) and if state and local codes, local inspection
    authorities, and the local utility permit the use of
    aluminum, and if approved by the BUILDER's Electrical
    Engineer.
    the >***< is a paragraph number/delimiter. The above is just a fraction of the entire file(there are 310 sections)
    I have a program now that uses text files. I want to use a RTB because the indentations under copper and aluminum in a text file are simply spaces. When someone adds text to the file the returns and spaces mess up the formatting.
    Lets say I select section >078<. How do I pull that out and the formatting? I will take these individual sections and place them into a composite RTB to compose the final document.
    Is there a better way to allow a user to select a number of formatted sections?
    I am so skeptical, I can hardly believe it!
    PS I am not a 'hyperactive member' I am a cool, calm, and collected member

  2. #2
    Frenzied Member
    Join Date
    Jan 2000
    Location
    Bellevue, WA, USA
    Posts
    1,357

    This might help...

    ...your signature

    correct spelling = skeptical


  3. #3

    Thread Starter
    Hyperactive Member badgers's Avatar
    Join Date
    Sep 1999
    Location
    Madison, WI USA
    Posts
    444
    I don't know. I will have to check that spelling I am skeptical of other people

  4. #4

    Thread Starter
    Hyperactive Member badgers's Avatar
    Join Date
    Sep 1999
    Location
    Madison, WI USA
    Posts
    444
    here is what I have come up with so far.
    Code:
    Option Explicit
    Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long,_
    ByVal wMsg As Long,ByVal wParam As Long, lParam As Any) As Long
    Const WM_COPY = &H301
    Const WM_CUT = &H300
    Const WM_PASTE = &H302
    Dim section(350) As String ' this array will hold the specification 
    'and will be available to all forms
    'this project has 2 rich text boxes. RTB1 and RTB2. RTB1 is visable=false. 
    'It holds the master specification file. RTB2 is the target and is also used
    'as an intermediate storage/file manipulator
    Private Sub CmdFLB_Click() 'Fill List Box, this is a very slow process I have about 300 paragraphs
    Dim i As Long, j As Long, k As Long
    k = 1
    RTB2.TextRTF = "" 'clear the text box
    While k > 0 'k will become -1 at the end
        j = RTB1.Find("<", j) 'find the back end of the delimiter
        If j Then 'If I find the delimiter make  a new section
            k = RTB1.Find(">", j) 'k will be the begining of the next section(-1 if it is the end)
            If k > 1 Then 'check for the end
              RTB1.SelStart = j + 1 'give me the begining of the section
              RTB1.SelLength = k - j - 1 'get me to the end of the section
              SendMessage RTB1.hwnd, WM_COPY, 0, 0 'extract the rich text
              SendMessage RTB2.hwnd, WM_PASTE, 0, 0 'place it in RTB2
              section(i) = RTB2.TextRTF 'add the rich text to the array
              List1.AddItem (RTB2.Text) 'add ascii text to the list box headings
              i = i + 1 'bump the array counter
              j = k + 1 'move the start point  for the text search
              RTB2.TextRTF = "" 'clear RTB2 so I can start again
            End If
        End If
    Wend
    End Sub
    
    Private Sub CmdMake_Click() 'make the final document in RTB2
    Dim i As Long
    RTB2.TextRTF = "" 'clear out the text box
    For i = 0 To (List1.ListCount - 1) ' run through all the sections
        If (List1.Selected(i)) Then ' if the item is checked then find the corresponding array item
           Clipboard.Clear 'clear the clipboard
           Clipboard.SetText section(i), vbCFRTF 'put the array section on the clipboard
           RTB2.SelStart = Len(RTB2.TextRTF) 'set the text start point to the end
           SendMessage RTB2.hwnd, WM_PASTE, 0, 0 'put the new section on the end of the document
         End If
    Next i
    End Sub
    In the CmdMake_click() sub I use the clipboard simply because I could not figure out how to make a direct insertion and maintain the formatting of the text. If anyone has any ideas I would love to hear them
    also the CmdFLB_Click() sub is super slow for large files. I have 310 sections. this sub chuggs along and takes almost 20 sec to fill the list box.(the list box has style=checkbox).
    The final program will run the code in CmdFLB_Click() just after form load(I need RTB1 to have the info). It is just on a command button for testing purposes.
    any body have a faster way to sort through this stuff and pull out the text. My first post has an example of how the RTB1 text looks. This thing pulls out the >***< and keeps the text and the FORMATTING.
    please help this thing technically works but it is very brute force. I need speed
    thank you for your time and have a good day

  5. #5

    Thread Starter
    Hyperactive Member badgers's Avatar
    Join Date
    Sep 1999
    Location
    Madison, WI USA
    Posts
    444
    Is there a way to by pass the clipboard?
    Does anyone see a way to optimize the parsing of the file into the listbox?
    thank you for your time and have a good day

  6. #6

    Thread Starter
    Hyperactive Member badgers's Avatar
    Join Date
    Sep 1999
    Location
    Madison, WI USA
    Posts
    444
    I have the following question regarding Rich text files
    When I parse the sections I end up with an extraneous return.
    I would like to use the replace function to strip out the first return. When I use the VbCrLf constant I find nothing.
    In the following text2 is a Rich Text Box(I know it sounds stupid)

    Text2.TextRTF = Replace(Text2.TextRTF, vbCrLf, "", 1, 1)

    the above finds zero, zip, nada.
    what is the code for a paragraph marker in a Rich Text Box?
    thank you for your time and have a good day

  7. #7

    Thread Starter
    Hyperactive Member badgers's Avatar
    Join Date
    Sep 1999
    Location
    Madison, WI USA
    Posts
    444
    disregard I am a tard
    anyone know how to bypass the clipboard in my code 3 replies up?
    how about speeding up the parsing of the RTF?
    thank you for your time and have a good day

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width