Solved

break up line values to a MSFlexGrid in vb6

Posted on 2014-09-04
5
181 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 47

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 47

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 47

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 47

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

Suggested Solutions

Title # Comments Views Activity
Adding to a VBA? 6 90
vb6 connector to mongodb 2 160
Visual Studio search word table and return Cell index 8 84
Automatic Email Reminder 4 94
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…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
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…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

737 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