Link to home
Start Free TrialLog in
Avatar of al4629740
al4629740Flag for United States of America

asked on

break up line values to a MSFlexGrid in vb6

I have a sample output from another program in Notepad that I would like to put into an MSFlexGrid in vb6

How can I take the values in the attached sample notepad file and organize it by the spaced values?
sample.txt
Avatar of Martin Liss
Martin Liss
Flag of United States of America image

Open the file in VB6, read it line by line into a variable called, say, strLine, and for each line then

Dim strParts() As String
strParts = Split(strLine, " ")


then strParts(0) will have the first section, str(1) the second, etc.
Avatar of al4629740

ASKER

Thank you.

I imagine I would use a loop.  When I open the notepad document, how would I start at the first line and finish on the last line within notepad.
In Notepad save the file. I saved my copy to "C:\temp\Q_28511807.txt

Then use the code shown below. In order to get things to line up in the right columns you may have to do things like the following after line 19.

strLine = Replace(strline, "Response Sent", "Response_Sent") ' so that the two words don't get split

Dim FF As Integer
Dim strParts() As String
Dim lngCol As Long
Dim strLine As String
Dim lngRow As Long

FF = FreeFile
' You may want to change the number of columns
MSFlexGrid1.Cols = 10

Open "C:\temp\Q_28511807.txt" For Input As FF

Do While Not EOF(FF)

    If MSFlexGrid1.Rows >= 2 Then
        MSFlexGrid1.Rows = MSFlexGrid1.Rows + 1
    End If
    
    Line Input #FF, strLine
    strParts = Split(strLine, " ")
    
    For lngCol = 0 To UBound(strParts) - 1
        MSFlexGrid1.TextMatrix(lngRow, lngCol) = strParts(lngCol)
    Next
    lngRow = lngRow + 1

Loop

Close

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Martin Liss
Martin Liss
Flag of United States of America image

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
I'm glad I was able to help.

In my profile you'll find links to some articles I've written that may interest you.
Marty - MVP 2009 to 2014