Time calculation add/delete in data grid getting problem

Discussion in 'Visual Basic ( VB )' started by viv345, Aug 9, 2010.

  1. viv345

    viv345 New Member

    Joined:
    Feb 22, 2010
    Messages:
    76
    Likes Received:
    0
    Trophy Points:
    0
    Time calculation add/delete in data grid getting problem while running
     

    Attached Files:

    • 1.jpg
      1.jpg
      File size:
      38.7 KB
      Views:
      975
    • 2.jpg
      2.jpg
      File size:
      80.4 KB
      Views:
      767
  2. enigmaCore

    enigmaCore New Member

    Joined:
    Aug 2, 2010
    Messages:
    4
    Likes Received:
    1
    Trophy Points:
    0
    Occupation:
    Student
    Location:
    Makati, Philippines
    Why do you still use VB6? Why there's need to learn VB6 when you can take the advantage of learning the new VB.NET?

    You know, there was a long battle about the migration to .NET. I don't know why some of you still used the supposed long-lost language.
     
    viv345 likes this.
  3. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,375
    Likes Received:
    388
    Trophy Points:
    83
    You may need to because no VB developer wants to migrate to .NEt unless he is compelled to.
     
    viv345 likes this.
  4. virxen

    virxen Active Member

    Joined:
    Nov 24, 2009
    Messages:
    387
    Likes Received:
    90
    Trophy Points:
    28
    send your project in a zip file plus the database you use
    in order to check it.
     
    viv345 likes this.
  5. viv345

    viv345 New Member

    Joined:
    Feb 22, 2010
    Messages:
    76
    Likes Received:
    0
    Trophy Points:
    0
    1. Not showing in Data grid
    2. Not Saving in DB20
     

    Attached Files:

  6. viv345

    viv345 New Member

    Joined:
    Feb 22, 2010
    Messages:
    76
    Likes Received:
    0
    Trophy Points:
    0
    And if I like to calculate the Grand Total of all Totals in a grid. HOW?
     
  7. virxen

    virxen Active Member

    Joined:
    Nov 24, 2009
    Messages:
    387
    Likes Received:
    90
    Trophy Points:
    28
    first of all why you send different code from the first post?

    now about your code
    there are many things you do not know.

    1) hours1 = CInt(Text2.Text)
    this will get you a runtime error 13 type mismatch
    if text2 is empty or if user entered a string instead of a number.
    if you use val(text2.text) instead you will have 0 as result

    2)If Text4.Text = 1 Then
    Text56.Text = 1 * 10#
    End If


    text4.text is a string and like this you must handle it
    the correct is
    Code:
    If val(Text4.Text) = 1 Then
       Text56.Text = cstr(1 * 10#)
       End If
    
    val(string)-->give us its numerical value
    Cstr(number)-->give us a string representing our number


    3) your form is misleading the user
    in the total hours column you have the hours and below the minutes
    but the labeling is not good.Try to make it better

    4)in a previous post of yours i had answered how to add and delete from datagrid
    but you did not use that in this project

    Code:
    Private Sub cmddelete_Click() 'delete button
    If Adodc1.Recordset.RecordCount <= 0 Then
    MsgBox "no record found"
    Exit Sub
    End If
    Dim answer As Integer
    answer = MsgBox("do you want to delete current record?", vbYesNoCancel, "DELETE")
    If answer = vbYes And Adodc1.Recordset.RecordCount > 0 Then Adodc1.Recordset.Delete
    Text1.Text = ""
    Text2.Text = ""
    Text3.Text = ""
    Text4.Text = ""
    Text5.Text = ""
    Text6.Text = ""
    Text7.Text = ""
    Text8.Text = ""
    Text9.Text = ""
    Text10.Text = ""
    End Sub
    
    the above code deletes the currently selected row of a datagrid and the record from database

    Code:
    Private Sub cmdadd_Click() 'Add New Record
    Adodc1.Recordset.AddNew
    Adodc1.Recordset.Fields("field1") = Text1.Text
    Adodc1.Recordset.Fields("field2") = Text2.Text
    Adodc1.Recordset.Fields("field3") = Text3.Text
    Adodc1.Recordset.Fields("field4") = Text4.Text
    Adodc1.Recordset.Fields("field5") = Text5.Text
    Adodc1.Recordset.Fields("field6") = Text6.Text
    Adodc1.Recordset.Fields("field7") = Text7.Text
    Adodc1.Recordset.Fields("field8") = Text8.Text
    Adodc1.Recordset.Fields("field9") = Text9.Text
    Adodc1.Recordset.Fields("field10") = Text10.Text
    Adodc1.Recordset.Update
    Text1.Text = ""
    Text2.Text = ""
    Text3.Text = ""
    Text4.Text = ""
    Text5.Text = ""
    Text6.Text = ""
    Text7.Text = ""
    Text8.Text = ""
    Text9.Text = ""
    Text10.Text = ""
    End Sub
    the above code inserts data in datagrid and in database

    Code:
    Private Sub cmdTotalGrid_Click()
    Dim i, a As Integer
    a = 0
    Adodc1.Recordset.MoveFirst 'Move the record position to the first
    'Iteration for row by row
    For i = 1 To Adodc1.Recordset.RecordCount
        'Calculate the result
        a = a + Val(DataGrid1.Columns(9).Text)
        Adodc1.Recordset.MoveNext
    Next
    MsgBox "result=" + CStr(a)
    End Sub
    
    the above code adds all the data stored in field10 column

    and your project with the changes is here
     

    Attached Files:

    viv345 and shabbir like this.
  8. viv345

    viv345 New Member

    Joined:
    Feb 22, 2010
    Messages:
    76
    Likes Received:
    0
    Trophy Points:
    0
    Thanks!
    I tried the same but giving problem
     

    Attached Files:

  9. viv345

    viv345 New Member

    Joined:
    Feb 22, 2010
    Messages:
    76
    Likes Received:
    0
    Trophy Points:
    0
    Sir
    And code given for calculating column what i do if i had to calculate Rows
     
  10. virxen

    virxen Active Member

    Joined:
    Nov 24, 2009
    Messages:
    387
    Likes Received:
    90
    Trophy Points:
    28
    did you connect the database correctly from the properties of Adodc1?
     
    shabbir and viv345 like this.
  11. virxen

    virxen Active Member

    Joined:
    Nov 24, 2009
    Messages:
    387
    Likes Received:
    90
    Trophy Points:
    28
    Code:
    Private Sub calcRow_Click()
    Dim i, a As Integer
    a = 0
    'Iteration for col by col for selected row
    For i = 0 To Adodc1.Recordset.Fields.Count - 2
        'Calculate the result
        a = a + Val(DataGrid1.Columns(i).Text)
    Next
    MsgBox "result=" + CStr(a)
    End Sub
    
     
    viv345 likes this.
  12. viv345

    viv345 New Member

    Joined:
    Feb 22, 2010
    Messages:
    76
    Likes Received:
    0
    Trophy Points:
    0
    yes database is properly connected with Adodc1
     
  13. viv345

    viv345 New Member

    Joined:
    Feb 22, 2010
    Messages:
    76
    Likes Received:
    0
    Trophy Points:
    0
    I tried it there were some mistakes I have made in the codings now it is working.
    THANKS!

    What I do if I want all the datagrid columns Total in another as an Summary of all?

    How can I display the TOTALS of All data grid.
     
    Last edited by a moderator: Aug 15, 2010
  14. viv345

    viv345 New Member

    Joined:
    Feb 22, 2010
    Messages:
    76
    Likes Received:
    0
    Trophy Points:
    0
    Sir,
    One more thing I made a Invoice Report. In which when I want to delete the data it gives error. Can you pl. check whats wrong.
     

    Attached Files:

  15. viv345

    viv345 New Member

    Joined:
    Feb 22, 2010
    Messages:
    76
    Likes Received:
    0
    Trophy Points:
    0
    One more thing When I use this code:-
    Private Sub cmdTotalGrid_Click()
    Dim i, a As Integer
    a = 0
    Adodc1.Recordset.MoveFirst 'Move the record position to the first
    'Iteration for row by row
    For i = 1 To Adodc1.Recordset.RecordCount
    'Calculate the result
    a = a + Val(DataGrid1.Columns(9).Text)
    Adodc1.Recordset.MoveNext
    Next
    MsgBox "result=" + CStr(a)
    End Sub

    It gives error in

    Private Sub cmddelete_Click()
    If Adodc1.Recordset.RecordCount > 0 Then
    Adodc1.Recordset.Delete
    Else
    MsgBox "no record found"
    End If
    End Sub


    Saying either BOF or EOF is true , or the
    current record has been deleted.
    Requested operation requires a current record.
     

    Attached Files:

  16. viv345

    viv345 New Member

    Joined:
    Feb 22, 2010
    Messages:
    76
    Likes Received:
    0
    Trophy Points:
    0
    One more thing When I use this code:-
    Private Sub cmdTotalGrid_Click()
    Dim i, a As Integer
    a = 0
    Adodc1.Recordset.MoveFirst 'Move the record position to the first
    'Iteration for row by row
    For i = 1 To Adodc1.Recordset.RecordCount
    'Calculate the result
    a = a + Val(DataGrid1.Columns(9).Text)
    Adodc1.Recordset.MoveNext
    Next
    MsgBox "result=" + CStr(a)
    End Sub

    It gives error in

    Private Sub cmddelete_Click()
    If Adodc1.Recordset.RecordCount > 0 Then
    Adodc1.Recordset.Delete
    Else
    MsgBox "no record found"
    End If
    End Sub


    Saying either BOF or EOF is true , or the
    current record has been deleted.
    Requested operation requires a current record.
     
  17. virxen

    virxen Active Member

    Joined:
    Nov 24, 2009
    Messages:
    387
    Likes Received:
    90
    Trophy Points:
    28
    Code:
    Private Sub cmdDelete_Click()
    If [COLOR=Red]rec.RecordCount [/COLOR]> 0 Then
    [COLOR=Red]rec.Delete[/COLOR]
    Else
    MsgBox "NO RECORD FOUND"
    End If
    End Sub
    
    its not adodc here
     
    viv345 and shabbir like this.
  18. virxen

    virxen Active Member

    Joined:
    Nov 24, 2009
    Messages:
    387
    Likes Received:
    90
    Trophy Points:
    28

    if you see the datagrid after the execution of cmdTotalGrid_click you will notice
    that there is no selected row.So by executing delete or calcRowTotal you will
    have an error produced.

    there are 2 solutions.

    1)
    Code:
    Private Sub cmdTotalGrid_Click()
    Dim i, a As Integer
    a = 0
    Adodc1.Recordset.MoveFirst 'Move the record position to the first
    'Iteration for row by row
    For i = 1 To Adodc1.Recordset.RecordCount
        'Calculate the result
        a = a + Val(DataGrid1.Columns(9).Text)
        Adodc1.Recordset.MoveNext
    Next
    MsgBox "result=" + CStr(a)
    [COLOR=Red]Adodc1.Recordset.MoveFirst'gets the header to first record (selects the first row)[/COLOR]
    
    End Sub
    2) check before you act
    Code:
    Private Sub cmddelete_Click() 'delete button
    If Adodc1.Recordset.RecordCount <= 0 Then
    MsgBox "no record found"
    Exit Sub
    End If
    [COLOR=Red]If Adodc1.Recordset.BOF = True Or Adodc1.Recordset.EOF = True Then
    MsgBox "no record selected"
    exit sub
    End If[/COLOR]'with this you check if a row(record) is selected
    ..............
    
     
    viv345 and shabbir like this.
  19. viv345

    viv345 New Member

    Joined:
    Feb 22, 2010
    Messages:
    76
    Likes Received:
    0
    Trophy Points:
    0
    THANKS

    Now their is one more problem or you can say my imagination i.e.

    I want to display the Datagrid Total in Separate form as an SUMMARY.

    How should I code for that?

    Same as we take the time calculation project when we click on calculate datagrid it gives result =10 I want this [THIS RESULT = 10] in separate form.

    Timecal.zip attached
     

    Attached Files:

    Last edited by a moderator: Aug 16, 2010
  20. virxen

    virxen Active Member

    Joined:
    Nov 24, 2009
    Messages:
    387
    Likes Received:
    90
    Trophy Points:
    28
    you have 2 forms in your project
    1) both will be visible at the same time?if not how will the second form become visible?pressing a command button for example?

    2)the second form will be informed immediately with the changes or you must press a button?

    3)why you use adodc in second form?

    4)in second form you have add and delete button.why?since this form is only
    for the results?
     
    viv345 likes this.

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice