Results 1 to 3 of 3

Thread: RESOLVED : problems with deleting row in msflexgrid..

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Apr 2004
    Location
    los angeles,ca
    Posts
    18

    RESOLVED : problems with deleting row in msflexgrid..

    HI guys,

    i am using an msflexgrid with a text file.
    the problem that i am having is that when i delete a row from the msflexgrid, and then i save all the information from the msflexgrid to the textfile, and then reload the flexgrid.,
    i see that what has really been deleted is the first column from all records, not the row that i had selected.

    here is the code i am using..
    maybe someone can show me an easier/better way to delete a row and then write the changes to my text file and reload the msflexgrid to show those changes.

    the text file has it's columns separted with a tab.
    here is the code I use for storing a record in the text file..I am putting it here so you can get an idea of how my text file is structured.
    ******************************
    Private Sub SaveButton_Click()


    'this is the number of your file
    Dim intFilenum As Integer

    'set it to the next available free number
    intFilenum = FreeFile

    'this is your filename
    Dim strFile As String
    strFile = App.Path & "\hamlogbook.txt"

    'this is the text you want to save (textbox)
    Dim strText As String
    strText = Callsign.Text & Chr$(9) & Me.Date.Text & Chr$(9) & Me.Band.Text & Chr$(9) & Me.Freq.Text & Chr$(9) & Me.Mode.Text & Chr$(9) & Me.HisRST.Text & Chr$(9) & Me.MyRST.Text & Chr$(9) & Me.Notes.Text

    'open the file for writing to as next freefile number

    Open strFile For Append As intFilenum 'see above options
    'write to the file
    Print #intFilenum, strText 'to read use [input #filenum,strtext]

    'close the file
    Close intFilenum

    End Sub
    *******************************
    thanks for your help...
    kevin rea
    kevinrea@adelphia.net



    here is the code that I am currently using to delete the one row / record and then to re-write the msflexgrid to the text file...
    *******************************************************************
    Private Sub CommandButton3_Click()

    Dim ans As String
    Beep
    ans = MsgBox("Are you sure you wish to delete this Entry?", vbYesNo, "Delete Entry")
    If ans = vbYes Then

    MSFlexGrid1.RemoveItem MSFlexGrid1.RowSel


    'write the new data from the flexgrid to the text file

    Dim f As Integer
    Dim r As Integer
    Dim c As Integer
    Dim LineText As String
    f = FreeFile
    Open App.Path & "\hamlogbook.txt" For Output As #f
    For r = 0 To MSFlexGrid1.Rows - 1
    LineText = MSFlexGrid1.TextMatrix(r, 1) 'First col (no tab needed)
    For c = 1 To MSFlexGrid1.Cols - 1
    LineText = LineText & Chr$(9) & MSFlexGrid1.TextMatrix(r, c)
    Next c
    Print #f, LineText
    Next r
    Close #f

    'end of writing new data from flexgrid to the text file

    Else
    Exit Sub
    End If

    End Sub
    *******************************************************

    I am attaching a copy of the text file that I am using...
    Attached Files Attached Files
    Last edited by kevinrea; Aug 2nd, 2006 at 03:02 PM.

  2. #2
    Oi, fat-rag! bushmobile's Avatar
    Join Date
    Mar 2004
    Location
    on the poop deck
    Posts
    5,592

    Re: problems with deleting row in msflexgrid..

    Consider this loop:
    VB Code:
    1. For r = 0 To MSFlexGrid1.Rows - 1
    2.     LineText = MSFlexGrid1.TextMatrix(r, 1) 'First col (no tab needed)
    3.     For c = 1 To MSFlexGrid1.Cols - 1
    4.         LineText = LineText & Chr$(9) & MSFlexGrid1.TextMatrix(r, c)
    5.     Next c
    6.     Print #f, LineText
    7. Next r
    this is what it's doing:
    Code:
    Enters r loop
        LineText = MSFlexGrid1.TextMatrix(0, 1)
        Enters c loop
            LineText = LineText & vbTab & MSFlexGrid1.TextMatrix(0, 1)
            LineText = LineText & vbTab & MSFlexGrid1.TextMatrix(0, 2)
            ' etc.
    You're actually writing the 2nd column (remember FlexGrids are 0-based) of the the FlexGrid to the text file twice.

    (you can also use the vbTab constant instead of Chr$(9))

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Apr 2004
    Location
    los angeles,ca
    Posts
    18

    Re: problems with deleting row in msflexgrid..

    thanks bushmobile !

    kevin

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