Visual Basic Code , VB.NET Code, VB Code
  Home   :  Code   :  Forums   :  Submit   :  Mailing List   :  About   :  Contact


who can explain that" doubled value"


who can explain that" doubled value"

Author
Message
Username
Username
Forum God
Forum God (1.7K reputation)Forum God (1.7K reputation)Forum God (1.7K reputation)Forum God (1.7K reputation)Forum God (1.7K reputation)Forum God (1.7K reputation)Forum God (1.7K reputation)Forum God (1.7K reputation)Forum God (1.7K reputation)

Group: Forum Members
Posts: 5, Visits: 25
hello

this is my first post in this forum and it has a small question

why do we get a doubled value when we calculate column in VB.net

i use this code

Dim i As Integer = 0

Dim total As Double

For i = 0 To ItemsDataGridView.RowCount - 1

total += ItemsDataGridView.Rows(i).Cells(3).Value

Next

TotalTextBox.Text = total


zack
zack
Forum God
Forum God (25K reputation)Forum God (25K reputation)Forum God (25K reputation)Forum God (25K reputation)Forum God (25K reputation)Forum God (25K reputation)Forum God (25K reputation)Forum God (25K reputation)Forum God (25K reputation)

Group: Forum Members
Posts: 102, Visits: 110
You mean the value is double what it should be or the data type is type double.
Username
Username
Forum God
Forum God (1.7K reputation)Forum God (1.7K reputation)Forum God (1.7K reputation)Forum God (1.7K reputation)Forum God (1.7K reputation)Forum God (1.7K reputation)Forum God (1.7K reputation)Forum God (1.7K reputation)Forum God (1.7K reputation)

Group: Forum Members
Posts: 5, Visits: 25
please check the attached pic.

it only counts one row and double it

Attachments
test form.jpg (401 views, 50.00 KB)
zack
zack
Forum God
Forum God (25K reputation)Forum God (25K reputation)Forum God (25K reputation)Forum God (25K reputation)Forum God (25K reputation)Forum God (25K reputation)Forum God (25K reputation)Forum God (25K reputation)Forum God (25K reputation)

Group: Forum Members
Posts: 102, Visits: 110
Ok, I see what you mean. I believe you're having this problem because you have defined i as an integer variable set to zero at the top. When you created your For Next loop a new counter variable was set just for the counter. So you have two different i variables.



The i variable in ItemsDataGridView.Rows(i) is always set to zero because you defined it above as zero. Try removing the line



Dim i As Integer = 0, and lets see what happens.



Your code should be,



Dim total As Double



For i = 0 To ItemsDataGridView.RowCount - 1



total += ItemsDataGridView.Rows(i).Cells(3).Value



Next



TotalTextBox.Text = total
Username
Username
Forum God
Forum God (1.7K reputation)Forum God (1.7K reputation)Forum God (1.7K reputation)Forum God (1.7K reputation)Forum God (1.7K reputation)Forum God (1.7K reputation)Forum God (1.7K reputation)Forum God (1.7K reputation)Forum God (1.7K reputation)

Group: Forum Members
Posts: 5, Visits: 25
The same

By the way, the total text box is one of the database tables but when i add i new text box i don't have a problem it give me the right total for the column

Username
Username
Forum God
Forum God (1.7K reputation)Forum God (1.7K reputation)Forum God (1.7K reputation)Forum God (1.7K reputation)Forum God (1.7K reputation)Forum God (1.7K reputation)Forum God (1.7K reputation)Forum God (1.7K reputation)Forum God (1.7K reputation)

Group: Forum Members
Posts: 5, Visits: 25
Ok i found the error

Wink

I found a line in total text changed

It gives me the total



By the way, it woked even with

Dim i as intiger =0



Thank you for your help



But when i add a new invoice all old items shown for the new invoice

GO


Similar Topics


Reading This Topic


Login
Existing Account
Email Address:


Password:


Social Logins

Select a Forum....

















A1VBCode Forums


Search