1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Time calculation add/delete in data grid getting problem

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

  1. virxen

    virxen New Member

    Joined:
    Nov 24, 2009
    Messages:
    387
    Likes Received:
    90
    Trophy Points:
    0
    make a control array of grids and add the totals of each one of them to get the
    desired total

    p.s. you have 2 different programs its better to split them into different threads not all together.
    you make everyone confused.
     
    Last edited: Aug 29, 2010
  2. viv345

    viv345 New Member

    Joined:
    Feb 22, 2010
    Messages:
    76
    Likes Received:
    0
    Trophy Points:
    0
    Sorry!
    It is all in one program. But every form contains different labels, datagrid and commands. I have tried to make it more simple. I am attaching the Project in zip. Now in this only one form contains two data grid. And each form I have used option buttons for calculation and One command button to get the Total from the grid into the text box. After getting the totals from each form in a Text box, their is a Summary button to go to the Summary form. In Summary form their are also a option buttons and text boxes and one command button GET to collect the totals into the text boxes.

    It is all in one program. But every form contains different labels, datagrid and commands. I have tried to make it more simple. I am attaching the Project in zip.

    My previous project long and confusing. It was not only confusing me but also the others.

    So now i have altered my project into simple one. No confusions.

    The problem is same to get Total of all data entered into Data Grid into a text box by click the command Total. In form 16 to get the totals by selecting option buttons.
     

    Attached Files:

    Last edited by a moderator: Aug 30, 2010
  3. virxen

    virxen New Member

    Joined:
    Nov 24, 2009
    Messages:
    387
    Likes Received:
    90
    Trophy Points:
    0
    why do you use so many databases?
    use only one with many tables its better approach.
     
    viv345 likes this.
  4. viv345

    viv345 New Member

    Joined:
    Feb 22, 2010
    Messages:
    76
    Likes Received:
    0
    Trophy Points:
    0
    just to avoid big size files.

    O. K. I will try to make it one?
     
    Last edited by a moderator: Aug 30, 2010
  5. virxen

    virxen New Member

    Joined:
    Nov 24, 2009
    Messages:
    387
    Likes Received:
    90
    Trophy Points:
    0
    1) all your forms (except form1) must have this code
    Code:
    Private Sub Form_Unload(Cancel As Integer)
    Rs.Close
    conn.Close
    Form1.Visible = True
    End Sub
    
    because if you close one of yours forms you see nothing.The control must be returned
    to form1.

    2)
    this is wrong,the correct name is form_Unload regardless of form's name(for example form2)

    3) try using names for your forms and controls to make your code readable.
    you have 8 forms form1,.. form16. Make use of the (name) property to give names to help you in programming
    for example text2 is better or txtRate?

    you can use the first 3 letters to indicate what this control is and then a name with a meaning starting with a capital letter.
    txt=textbox
    frm=form
    lbl=label
    cmd=command button
    opt=option button
    cmb=combo box
    and so on
    for example frmPhotostat is better than just form2!


    4)


    in this post was the answer for your first question did you notice? :disappoin
    just change your code to look like this in form2

    Code:
    [COLOR=Blue]Private Sub Command10_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([COLOR=Red]2[/COLOR]).Text)
        Adodc1.Recordset.MoveNext
    Next
    [COLOR=Red]Text32.Text = CStr(a)[/COLOR]
    Adodc1.Recordset.MoveFirst 'gets the header to first record (selects the first row)
    End Sub[/COLOR]
    

    and finally i will answer your second question when you post again your project with the changes,and all totals working okay according to the above.

    p.s. your project with only one database is here
     

    Attached Files:

    Last edited: Aug 30, 2010
    shabbir likes this.
  6. viv345

    viv345 New Member

    Joined:
    Feb 22, 2010
    Messages:
    76
    Likes Received:
    0
    Trophy Points:
    0
    Can i create new database using coding. If yes then How?
     
  7. virxen

    virxen New Member

    Joined:
    Nov 24, 2009
    Messages:
    387
    Likes Received:
    90
    Trophy Points:
    0
    database or database table you mean?
     
  8. viv345

    viv345 New Member

    Joined:
    Feb 22, 2010
    Messages:
    76
    Likes Received:
    0
    Trophy Points:
    0
    db file with table
     
  9. viv345

    viv345 New Member

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

    getting problem in calculating row by row?
    Project attached
     

    Attached Files:

  10. virxen

    virxen New Member

    Joined:
    Nov 24, 2009
    Messages:
    387
    Likes Received:
    90
    Trophy Points:
    0
    viv345 likes this.
  11. virxen

    virxen New Member

    Joined:
    Nov 24, 2009
    Messages:
    387
    Likes Received:
    90
    Trophy Points:
    0
    Re: calculation add/delete in data grid getting problem


    programming is not just a copy paste

    Code:
    Private Sub cmdtotalrow_Click()
    Dim i, a As Integer
    a = 0
    'Iteration for col by col for selected row
    For i = [COLOR="Red"]0[/COLOR] To Adodc1.Recordset.Fields.Count - 2
        'Calculate the result
        [COLOR=Blue]MsgBox DataGrid1.Columns(i).Text[/COLOR] '[COLOR=Red]add this command and see what you add[/COLOR]
        a = a + Val(DataGrid1.Columns(i).Text)
    Next
    MsgBox "result=" + CStr(a)
    Text8.Text = CStr(a)
    Adodc1.Recordset.MoveFirst
    End Sub
    
     

Share This Page