0

Hi everyone, im new to this fourm. Ok i'm working on a dgv page, every time i fill out my text boxes ect. i press add transaction button i got.
Information shows up in the dgv, but then theres 2 columns i want to have the total sum show up in 2 seperate textboxes everytime i hit the add transaction button.
I got 2 seperate check boxes plus the 2 seperate textboxes.The one check box is for income the other is for expense. Same with the columns.
If i fill cells 5 first then also cells 4 it works fine.But then if i try to go back to filling out cell5 i get an error` total += Convert.ToDouble(DataGridView1.Rows(i).Cells(4).Value)

Hope this makes enough sense so somone can help. Thnaks!

 Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        If ExRB.Checked Then
            DataGridView1.Rows.Add(DateTimePicker1.Text, ComboBox1.Text, TextBox5.Text, TextBox6.Text, "", TextBox.Text)
            Dim total As Double = 0
            For index As Integer = 0 To DataGridView1.RowCount - 1
                If Not IsDBNull(DataGridView1.Rows(index).Cells(5).Value) Then
                    total += Convert.ToDouble(DataGridView1.Rows(index).Cells(5).Value)
                End If
            Next
            Label11.Text = total.ToString
        ElseIf InRB.Checked Then
            DataGridView1.Rows.Add(DateTimePicker1.Text, ComboBox1.Text, TextBox5.Text, TextBox6.Text, TextBox.Text)
            Dim total As Double = 0
            For i As Integer = 0 To DataGridView1.RowCount - 1
                total += Convert.ToDouble(DataGridView1.Rows(i).Cells(4).Value)
            Next
            Label10.Text = total.ToString
        End If
        ComboBox1.Text = ""
        TextBox5.Text = ""
        TextBox6.Text = ""
        TextBox.Text = ""
    End Sub
5
Contributors
8
Replies
55
Views
6 Months
Discussion Span
Last Post by ddanbe
0

Here's a thing. Your topic doesn't seem to match what you ask in the text below.

So beside that, in the IDE break on the error line and examine variables to see what the issue is.

0

Saying you have an error tells us little to help solve your problem.
What is the error? What value do some values have? Your stack trace. Please show us that information.

0

Line # 15

Exception:Thrown: "Input string was not in a correct format." (System.FormatException)
A System.FormatException was thrown: "Input string was not in a correct format."
Time: 06/04/2017 8:41:15 PM
Thread:<No Name>[7696]
Attachments Untitled.png 15.6 KB
0

Well, that's a start. :)
Now set some breakpoints in this code and see what happens and let us know. A FormatException is usually not that hard to find out.

1

I wonder why your line #15 isn't wrap like line #7 with If Not IsDBNull... because in case ...cells(4).value is DBNull because of an empty input, an exception will occur.

Votes + Comments
Nulls are small slug-like creatures of limited intelligence who drain energy.
0

Ok sorry this is not working yet. I will start with a new topic

0

No, please don't. Why start another thread to go over the same ground again?

<too late> <sigh>

I have closed your other thread, and posted saying that the discussion/help should continue here.

Edited by happygeek

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.