I am trying to incorporate MSFlexgrid to read all the data from a text file but i am currently having a problem with a line

Below is the coding

Private Sub Command1_Click()

MSFlexGrid1.Cols = kiraCols + 1
Open App.Path & "\master_data.txt" For Input As #1 '
linecount = 1

Do While Not EOF(1)
Line Input #1, Readline1
With MSFlexGrid1

'text
.Rows = .Rows + 1
.row = .Rows - 1
.col = 0
.Text = Readline1.Text
.col = 2
.Text = Readline1.Text
.col = 3
.Text = Readline1.Text


linecount = linecount + 1
End With
Loop
Close #1
End Sub


Sample of the data in the text file:

51.370E+00
51.370E+00
51.370E+00
51.370E+00

the problem is on the line ".Text = Readline1.Text" and so on....so....please....can anyone help me.....thank you very much........

You need to specify in which column to add the text. Try and use -

MSFlexGrid1.Columns(x).Text = Readline1.Text

'You will have to code the value of column x, or just use as you had i.e. 0, 2, 3

Is this correct?

.Columns(1).Text = Readline1.Text

but it said "member or data not found" and highlighted the ".Columns"

I just started learning vb on my own so; sorry if i am clueless

I have duplicated your requirement and changed the code to the following which is now working 100% -

Private Sub Command2_Click()

Dim strFilename As String
Dim strText As String
Dim strFilter As String
Dim strBuffer As String
Dim FileHandle As String
Dim LineCount As Long

strFilter = App.Path & "\master_data.txt"
LineCount = 1

If strFilter <> vbNullString Then
    strFilename = strFilter
    FileHandle = FreeFile
    
    Open strFilename For Input As #FileHandle
    
    Do While Not EOF(FileHandle)
        Line Input #FileHandle, strBuffer
        strText = strText & strBuffer '& vbCrLf
               
        Readline1.Text = strText

    With MSFlexGrid1
        .Cols = 3
        .Rows = .Rows + 1
        .Row = .Rows - 1
        .Col = 0
        .Text = Readline1.Text
        .Col = 1
        .Text = Readline1.Text
        .Col = 2
        .Text = Readline1.Text
        
        LineCount = LineCount + 1
    End With
    Loop
End If

Close #FileHandle
End Sub

Thanks! It helped a lot! My sincere thanks to you AndreRet.

Only a pleasure Khairil.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.