Solved

break up line values to a MSFlexGrid in vb6

Posted on 2014-09-04
5
160 Views
Last Modified: 2014-09-15
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
0
Comment
Question by:al4629740
  • 4
5 Comments
 
LVL 45

Expert Comment

by:Martin Liss
ID: 40304363
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.
0
 

Author Comment

by:al4629740
ID: 40304631
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.
0
 
LVL 45

Expert Comment

by:Martin Liss
ID: 40304732
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

0
 
LVL 45

Accepted Solution

by:
Martin Liss earned 500 total points
ID: 40304835
Here's a modification that lines up the first 4 columns. Let me know if they are correct and what you'd like to see in the rest of the columns.

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 = 9

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
    ' Add underscores so the phrase isn't split up
    strLine = Replace(strLine, "IP response", "IP_response")
    strLine = Replace(strLine, "esponse sent", "esponse_sent")

    strParts = Split(strLine, " ")
    
    For lngCol = 0 To UBound(strParts)
        ' replace the added underscores with a space
        strParts(lngCol) = Replace(strParts(lngCol), "_", " ")
        MSFlexGrid1.TextMatrix(lngRow, lngCol) = strParts(lngCol)
    Next
    lngRow = lngRow + 1

Loop

Close

Open in new window

0
 
LVL 45

Expert Comment

by:Martin Liss
ID: 40324391
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
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now