i have a dgv and i want to calculate marks. the dgv accepts string format from access db datatype set to text and sums various columns, To be able to sum the cells value i use the code below which works fine. My question is how to improve the decision making part so that at some point it can re-accept string format to allow for both numbers as well as string operations. at the same time the dgv encounters empty strings.
'Function Overloading with Decision Making in a type cast Private Function GetIntOnly(ByVal value As String) As Integer Dim x As Int16 For j As Int16 = 0 To dgw.Columns.Count - 1 For r As Int16 = 0 To dgw.Rows.Count - 1 If value = "" Then value = "" Else x = value.ToString End If Next Next Return x End Function
'I call the function whenever I sum dgv cell value using the overload something like this .. Private Function AddElement() Return Compulsory() + Sciences() + humanities() + Booster() End Function Public Function Compulsory() As Int16 Dim c As Int16 For r As Int16 = 0 To dgw.Rows.Count - 1 c = GetIntOnly(dgw.Rows(r).Cells("english").Value.ToString) + GetIntOnly(dgw.Rows(r).Cells("kiswahili").Value.ToString) + GetIntOnly(dgw.Rows(r).Cells("Mathematics").Value.ToString) dgw.Rows(r).Cells("total").Value = c Next Return c End Function
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)