Time calculation add/delete in data grid getting problem

Contributor
9Aug2010,10:20   #1
viv345's Avatar
Time calculation add/delete in data grid getting problem while running
Attached Images
File Type: jpg 1.jpg (38.7 KB, 6 views)
File Type: jpg 2.jpg (80.4 KB, 9 views)
Newbie Member
9Aug2010,13:37   #2
enigmaCore's Avatar
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 like this
Go4Expert Founder
9Aug2010,15:26   #3
shabbir's Avatar
Quote:
Originally Posted by enigmaCore View Post
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.
You may need to because no VB developer wants to migrate to .NEt unless he is compelled to.
viv345 like this
Pro contributor
10Aug2010,03:56   #4
virxen's Avatar
send your project in a zip file plus the database you use
in order to check it.
viv345 like this
Contributor
12Aug2010,17:10   #5
viv345's Avatar
1. Not showing in Data grid
2. Not Saving in DB20
Attached Files
File Type: zip Time Cal.zip (24.5 KB, 6 views)
Contributor
12Aug2010,17:36   #6
viv345's Avatar
And if I like to calculate the Grand Total of all Totals in a grid. HOW?
Pro contributor
13Aug2010,04:43   #7
virxen's Avatar
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
File Type: rar timecalc.rar (16.8 KB, 7 views)
shabbir, viv345 likes this
Contributor
14Aug2010,19:04   #8
viv345's Avatar
Thanks!
I tried the same but giving problem
Attached Images
File Type: jpg ScreenShot001.JPG (173.3 KB, 3 views)
File Type: jpg ScreenShot002.jpg (130.5 KB, 3 views)
Contributor
14Aug2010,19:37   #9
viv345's Avatar
Sir
And code given for calculating column what i do if i had to calculate Rows
Pro contributor
15Aug2010,04:22   #10
virxen's Avatar
Quote:
Originally Posted by viv345 View Post
Thanks!
I tried the same but giving problem
did you connect the database correctly from the properties of Adodc1?
shabbir, viv345 likes this