Link to home
Start Free TrialLog in
Avatar of rrh187
rrh187

asked on

Quick Parsing on click event

I want do a quick parsing routine on click event ...  In my app I'm using the Cmdialog to
open a file "test.txt" in a rich textbox.  The file when will look like this when it's open:

P13XW107456  74      15 T                             8877                     1
P10XW107760  74      15 T                             8878                     1
P13XW101530  74      15 T                             8879                     1

I would like the file to look like this after a click event:

P13XW107456  8877                  
P10XW107760  8878                    
P13XW101530  8879

Any suggestions??                      Thanks, rrh187
Avatar of deighton
deighton
Flag of United Kingdom of Great Britain and Northern Ireland image

Here is how I'd do it without a richtext box - processing files directly

Processing the RTB could be tricky.

Private Sub Command1_Click()

    Dim a  As String
   
    Open "test.txt" For Input As #1
   
    Open "test2.txt" For Output As #2
   
    Line Input #1, a
 
    Do Until EOF(1)
   
               
        Print #2, Left(a, 11) & "   " & Mid(a, 30, 4)
        'you need to get the positioning right on mid e.g 30 along the 4 chars
       
        Line Input #1, a
               
    Loop
   
    Close #2
    Close #1
   
End Sub

Avatar of richtsteig
richtsteig

Do you want to save your changes back to the file
or just want to have two different ways to display
the information (toggle)?
This addresses the other comment:   He is using the LOADFILE method of the RTF box, so he does not need to read from file.


You can do this a couple ways.  here is one:

public sub ParseLikeRRH187Wants(rtf as RichTextBox)
   dim lLine as long
   dim lPos  as long
   dim lTemp as long
   dim lLineStart as long
   dim szLine     as string

   lLine = 1
   lLineStart = 1
   for lPos = 1 to len(rtf.text)
      lTemp = rtf.getlinefromchar(lPos)
      if lTemp > lLine then
         'get the line and fix it up
         lLine = lTemp
         szLine = mid$(rtf.text, lLineStart, lPos - lLineStart)
         szLine = left$(szLine, 11) & " " & mid$(szLine, 56, 4)
         rtf.selstart = lLineStart
         rtf.sellength = lLineStart - lPos
         rtf.Seltext = szline
         lLineStart = lPos
       end if
     next lPos
end sub
         
         
Avatar of rrh187

ASKER

25 Bonus to finish, I used deighton's example and it works great, and richsteig has an interesting ideal, I would like do this on the file that is loaded in the Rich TextBox, I'm not using the the Rich TextBox property "loadfile" I'm using the CMDialog to open different files, and when I do a click event I want the file to change. anthonyc I havn't got your soulition to work yet, I'm still kind-of new at this, but if Iget to work I will award you with the points.

                                                 Thanks for all of your help, rrh187
Avatar of rrh187

ASKER

hey did you guys forget about me???
ASKER CERTIFIED SOLUTION
Avatar of raider187
raider187

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial