• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 139
  • Last Modified:

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
0
rrh187
Asked:
rrh187
1 Solution
 
deightonCommented:
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

0
 
richtsteigCommented:
Do you want to save your changes back to the file
or just want to have two different ways to display
the information (toggle)?
0
 
anthonycCommented:
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
         
         
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
rrh187Author Commented:
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
0
 
rrh187Author Commented:
hey did you guys forget about me???
0
 
raider187Commented:
Use the click event to copy and pase the file a open each ver to display them
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now