Solved

break up line values to a MSFlexGrid in vb6

Posted on 2014-09-04
5
168 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 46

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 46

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 46

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 46

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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

773 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