Loading MSFlexGrid in Form_Load()

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • MiziaQ
    New Member
    • Nov 2007
    • 63

    Loading MSFlexGrid in Form_Load()

    Hey. I have a problem. I am entering data into various textboxes and writing it to a file. I then reading that data in a MSFlexGrid table. I have no problem with that. The only problem is that when the application is closed, the current state of the table is not saved. How can I do that ?

    Here's my code, all under the AddDelivery button:

    Private Sub cmdAddDelivery_ Click()

    Open App.Path & "\deliveries.tx t" For Append As #11
    Write #11, txtPName.Text, txtPAddress1.Te xt & ", " & txtPAddress2.Te xt & ", " & cboPTown.Text, cboPPrefix.Text & " " & txtPTelephone.T ext & ", " & cboPMPrefix.Tex t & " " & txtPMobile.Text , txtDName.Text, txtDAddress1.Te xt & ", " & txtDAddress2.Te xt & ", " & cboDTown.Text, cboDPrefix.Text & " " & txtDTelephone.T ext & ", " & cboDMPrefix.Tex t & " " & txtDMobile.Text , txtWeightOfPack age.Text, txtDeliveryPric e.Text, txtPickupDate.T ext, txtDeliveryDate .Text

    MsgBox "New Delivery has been Added !", vbInformation, "Success!!! "

    txtPName.Text = ""
    txtPAddress1.Te xt = ""
    txtPAddress2.Te xt = ""
    cboPTown.Text = ""
    cboPPrefix.Text = "021"
    txtPTelephone.T ext = ""
    cboPMPrefix.Tex t = "085"
    txtPMobile.Text = ""

    txtDName.Text = ""
    txtDAddress1.Te xt = ""
    txtDAddress2.Te xt = ""
    cboDTown.Text = ""
    cboDPrefix.Text = "021"
    txtDTelephone.T ext = ""
    cboDMPrefix.Tex t = "085"
    txtDMobile.Text = ""
    txtWeightOfPack age.Text = ""
    txtDeliveryPric e.Text = ""
    txtPickupDate.T ext = ""
    txtDeliveryDate .Text = ""

    txtPName.SetFoc us

    Close #11

    Open App.Path & "\deliveries.tx t" For Input As #12

    Dim oldRow As Long
    Dim lngRow As Long
    Dim lngCol As Long

    Dim strID As String
    Dim strPickupName As String
    Dim strPickupAdd As String
    Dim strPickupTel As String
    Dim strDelName As String
    Dim strDelAdd As String
    Dim strDelTel As String
    Dim strWoP As String
    Dim strDelPrice As String
    Dim strPriority As String
    Dim strPickupDate As String
    Dim strDelDate As String

    Dim counter As Integer

    counter = 1

    Do Until EOF(12)
    Input #12, strPickupName, strPickupAdd, strPickupTel, strDelName, strDelAdd, strDelTel, strWoP, strDelPrice, strPickupDate, strDelDate
    MSFlexGrid1.Tex tMatrix(counter , 0) = ""
    MSFlexGrid1.Tex tMatrix(counter , 1) = strPickupName
    MSFlexGrid1.Tex tMatrix(counter , 2) = strPickupAdd
    MSFlexGrid1.Tex tMatrix(counter , 3) = strPickupTel
    MSFlexGrid1.Tex tMatrix(counter , 4) = strDelName
    MSFlexGrid1.Tex tMatrix(counter , 5) = strDelAdd
    MSFlexGrid1.Tex tMatrix(counter , 6) = strDelTel
    MSFlexGrid1.Tex tMatrix(counter , 7) = strWoP
    MSFlexGrid1.Tex tMatrix(counter , 8) = strDelPrice
    MSFlexGrid1.Tex tMatrix(counter , 9) = strPickupDate
    MSFlexGrid1.Tex tMatrix(counter , 10) = strDelDate
    counter = counter + 1
    Loop

    MSFlexGrid1.Row s = MSFlexGrid1.Row s + 1
    For lngRow = MSFlexGrid1.Row s - 2 To MSFlexGrid1.Row Step -1
    For lngCol = 0 To MSFlexGrid1.Col s - 1
    MSFlexGrid1.Tex tMatrix(lngRow + 1, lngCol) = MSFlexGrid1.Tex tMatrix(lngRow, lngCol)
    If lngRow = MSFlexGrid1.Row Then
    MSFlexGrid1.Tex tMatrix(lngRow, lngCol) = "" 'Make the current row empty
    End If
    Next
    Next

    Close #12

    End Sub

    thanks
  • jamesd0142
    Contributor
    • Sep 2007
    • 471

    #2
    Under the froms closing event
    [write code]
    or
    [call function]
    to save

    Comment

    • mafaisal
      New Member
      • Sep 2007
      • 142

      #3
      Hello

      Try This

      In VB6

      Code:
      Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
        Call cmdAddDelivery_Click()
      End Sub
      
      or
      
      Private Sub Form_Unload(Cancel As Integer)
        Call cmdAddDelivery_Click()
      End Sub
      in .Net Call function Form Close Event

      Faisal

      Comment

      • MiziaQ
        New Member
        • Nov 2007
        • 63

        #4
        I did that and I get an error 381, subscript out of range,
        it's highlighting MSFlexGrid1.Tex tMatrix(counter , 0) = ""

        Comment

        • mafaisal
          New Member
          • Sep 2007
          • 142

          #5
          Hello

          Here I think U donot Increment ur Rows of flexgrid,
          So the error subscript out of range is come
          Check the code using break pont and also hw many rows set ur grid and its no is increment in loop

          Faisal

          Originally posted by MiziaQ
          I did that and I get an error 381, subscript out of range,
          it's highlighting MSFlexGrid1.Tex tMatrix(counter , 0) = ""

          Comment

          Working...