Results 1 to 7 of 7

Thread: text file to msflexgrid

  1. #1

    Thread Starter
    Lively Member
    Join Date
    May 2006
    Posts
    120

    text file to msflexgrid

    i have data in the text file. i want to put the data in msflexgrid in three columns. how to write the code to do that?
    Attached Files Attached Files

  2. #2
    Member nf_vb's Avatar
    Join Date
    Mar 2007
    Location
    Portugal
    Posts
    35

    Re: text file to msflexgrid

    try this little example:

    Private fso As New FileSystemObject
    Private strName As String

    Private Sub readfile()

    strName = "C:\Output.txt"
    On Error GoTo a
    With fso
    Set strm = .OpenTextFile(strName, ForReading)
    With strm
    Do Until .AtEndOfStream
    For i = 0 To MSFlexGrid1.Rows
    For k = 0 To MSFlexGrid1.Cols
    MSFlexGrid1.TextMatrix(i, k) = MSFlexGrid1.TextMatrix(i, k) & .ReadLine
    Next k
    Next i
    Loop
    End With
    End With
    Exit Sub
    a:
    Exit sub
    End Sub

    Private Sub Command1_Click()
    readfile
    End Sub

  3. #3

    Thread Starter
    Lively Member
    Join Date
    May 2006
    Posts
    120

    Re: text file to msflexgrid

    Quote Originally Posted by nf_vb
    try this little example

    Private fso As New FileSystemObject
    Private strName As String

    Private Sub readfile()

    strName = "C:\Output.txt"
    On Error GoTo a
    With fso
    Set strm = .OpenTextFile(strName, ForReading)
    With strm
    Do Until .AtEndOfStream
    For i = 0 To MSFlexGrid1.Rows
    For k = 0 To MSFlexGrid1.Cols
    MSFlexGrid1.TextMatrix(i, k) = MSFlexGrid1.TextMatrix(i, k) & .ReadLine
    Next k
    Next i
    Loop
    End With
    End With
    Exit Sub
    a:
    Exit sub
    End Sub

    Private Sub Command1_Click()
    readfile
    End Sub
    i have try the code, but it came out an error "compile error: user defined type not defined" and point to the code (Private fso As New FileSystemObject)
    Last edited by junlo; Mar 30th, 2007 at 10:12 AM.

  4. #4
    Member nf_vb's Avatar
    Join Date
    Mar 2007
    Location
    Portugal
    Posts
    35

    Re: text file to msflexgrid

    add to vb6 references microsoft scriptting runtime

    and create a module with this code

    Public Const MAX_PATH = 260

    Type FILETIME ' 8 Bytes
    dwLowDateTime As Long
    dwHighDateTime As Long
    End Type

    Type WIN32_FIND_DATA ' 318 Bytes
    dwFileAttributes As Long
    ftCreationTime As FILETIME
    ftLastAccessTime As FILETIME
    ftLastWriteTime As FILETIME
    nFileSizeHigh As Long
    nFileSizeLow As Long
    dwReserved_ As Long
    dwReserved1 As Long
    cFileName As String * MAX_PATH
    cAlternate As String * 14
    End Type

    Public Declare Function FindFirstFile& Lib "kernel32" _
    Alias "FindFirstFileA" (ByVal lpFileName As String, lpFindFileData _
    As WIN32_FIND_DATA)

    Public Declare Function FindClose Lib "kernel32" _
    (ByVal hFindFile As Long) As Long

    Function FileFound(strFileName As String) As Boolean
    Dim lpFindFileData As WIN32_FIND_DATA
    Dim hFindFirst As Long
    hFindFirst = FindFirstFile(strFileName, lpFindFileData)

    If hFindFirst > 0 Then
    FindClose hFindFirst
    FileFound = True
    Else
    FileFound = False
    End If
    End Function

  5. #5

    Thread Starter
    Lively Member
    Join Date
    May 2006
    Posts
    120

    Re: text file to msflexgrid

    what function of microsoft scriptting runtime ??????

  6. #6
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: text file to msflexgrid

    Quote Originally Posted by junlo
    what function of microsoft scriptting runtime ??????
    Not a function, a reference.

    From your IDE, click Project/References

    Locate the Microsoft Scripting Runtime Library
    Check the box next to it
    Click Ok

  7. #7
    Member nf_vb's Avatar
    Join Date
    Mar 2007
    Location
    Portugal
    Posts
    35

    Re: text file to msflexgrid

    you need to add

    microsoft scripting runtime

    is in the list

    you need that to use file functions
    Last edited by nf_vb; Mar 30th, 2007 at 11:18 AM. Reason: error

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width