Solved

break up line values to a MSFlexGrid in vb6

Posted on 2014-09-04
5
186 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
5 Comments
 
LVL 48

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 48

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 48

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 48

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

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!

Question has a verified solution.

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

If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…

696 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