Results 1 to 4 of 4

Thread: popualte msflexgrid with a text file

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Oct 2001
    Location
    Richmond, VA
    Posts
    17

    Question popualte msflexgrid with a text file

    hi people,

    I am trying to open a text file and put the data into an msflexgrid. there are 2 problems here. first is i can not get the info into the grid. second is when i do somehow it only goes in on the first row of the grid and does not tab between columns. below is my code, can anyone see what the problem is.

    Private Sub cmdOpenFile_Click()

    Dim WeekNo As String
    Dim i, j As Integer
    Dim filerec As Integer
    Dim rec2 As String

    WeekNo = cboWeek.Text
    intNum = FreeFile
    CreateIndex
    Open "C:\Timesheets\" + WeekNo + ".txt" For Random As intNum Len = Len(WriteData)

    On Error Resume Next
    If numData > 0 Then
    ReDim Index(numData)
    CreateIndex
    End If
    Get #intNum, Index(Record).RecNum, WriteData

    rec2 = Trim(Index(Record).Date)
    If rec2 = Empty Then
    Record = Record + 1
    End If
    For i = 0 To Grid1.Rows - 1
    Get #intNum, Index(Record).RecNum, WriteData
    Record = Record + 1
    numData = LOF(1) / Len(WriteData)
    Seek #intNum, Loc(1) - 1
    For j = 0 To Grid1.Cols - 1
    With WriteData
    Grid1.TextMatrix(i, 0) = .dates
    Grid1.TextMatrix(i, 1) = .client
    Grid1.TextMatrix(i, 2) = .jobno
    Grid1.TextMatrix(i, 3) = .desc
    Grid1.TextMatrix(i, 4) = .types
    Grid1.TextMatrix(i, 5) = .time
    Grid1.TextMatrix(i, 6) = .adstfx
    Grid1.TextMatrix(i, 7) = .notes
    End With
    Next j
    Next i
    Close intNum
    End Sub

    Sub CreateIndex()
    Dim indexEntry As IndexType
    Dim i, j
    Dim temp As String

    For i = 1 To numData
    Get #intNum, i, WriteData
    temp = WriteData.dates
    Index(i).Date = temp
    Index(i).RecNum = i
    Next i

    For i = 1 To numData - 1
    For j = i + 1 To numData
    If Index(i).Date > Index(j).Date Then
    indexEntry = Index(i)
    Index(i) = Index(j)
    Index(j) = indexEntry
    End If
    Next j
    Next i
    End Sub

    i have been working on this for 3 days now so if anyone has any suggestions it would be greatly appreciated.

    thanks
    juli

  2. #2
    Guru Aaron Young's Avatar
    Join Date
    Jun 1999
    Location
    Red Wing, MN, USA
    Posts
    2,177
    It's hard to tell, seeing as you're using a type definition to hold the record data and haven't supplied the definition.

    If you want to post the project and a sample file, I'd be happy to look at it for you.

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Oct 2001
    Location
    Richmond, VA
    Posts
    17
    ok, in a module (called module1):

    Type Record
    dates As String * 10
    client As String * 6
    jobno As String * 10
    desc As String * 255
    types As String * 30
    time As String * 2
    adstfx As String * 12
    notes As String * 255
    End Type
    Public WriteData As Record

    Type IndexType
    Date As String * 10
    RecNum As Integer
    End Type
    Public Index() As IndexType
    Public numData As Integer
    Public Record As Integer
    juli

  4. #4

    Thread Starter
    Junior Member
    Join Date
    Oct 2001
    Location
    Richmond, VA
    Posts
    17

    almost there

    I almost got it now. I took out a lot of stuff that really wasn't necessary and it's working. Just one problem. when saving to the text file it keeps tabbing the first column so when i open the file the first column is 14 char. in from left. Can anyone see why it is doing this.

    My code:
    Public Sub cmdSaveToFile_Click()
    Dim griddata As String
    Dim WeekNo As String
    Dim i, j, intNum As Integer
    WeekNo = cboWeek.Text
    intNum = FreeFile

    Open "C:\Timesheets\" + WeekNo + ".txt" For Output As #intNum

    With Grid1
    For i = 1 To Grid1.Rows - 1
    griddata = ""
    For j = 0 To Grid1.Cols - 1
    griddata = griddata & .TextMatrix(i, j) & vbTab
    Next j
    Print #intNum, , griddata
    Next i
    End With
    Close #intNum
    MsgBox "File has been saved"
    GridText.Visible = False

    End Sub

    what it saves in text file
    10/18/02 abc ect... for 7 columns of data

    the date should be all the way to the left.

    any suggestions?

    ps. i tried to post the code with all the indentions but it alway comes out all to the left. sorry
    Last edited by mm711; Oct 18th, 2002 at 07:10 AM.
    juli

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