Click here to Skip to main content
15,879,348 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
Dear Friends ,

I Have One Doubt..If Anyone Know Please Help Me....

I Have 2 Text Boxes , 1 List Box And 1 Button .

When I Enter Decimal Numbers In Textbox 1 , Result is Coming Wrong....

For Exammple : First Number 10.50
Second Number 30.20

Normally The Correct Result is = 40.70

But In My Program Showing Only 40.....Not Showing That Decimal Numbers.....Pleae Help Me

Code is Below :

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        ListBox1.Items.Add(TextBox1.Text)


        Dim total As Integer
        For Each Str As String In ListBox1.Items
            total = total + CInt(Str)
        Next

        TextBox2.Text = total
    End Sub

End Class


Thanks in Advance.....Arjun....

[edit] SHOUTING removed - OriginalGriff [/edit]
Posted
Updated 16-Aug-13 19:51pm
v2
Comments
OriginalGriff 17-Aug-13 1:52am    
DON'T SHOUT!
Using all uppercase is considered shouting on the internet, and rude.
Arjun Kerala 17-Aug-13 2:20am    
Hi Sir...i Dont Understand..What you Mean ?
OriginalGriff 17-Aug-13 2:26am    
http://en.m.wikipedia.org/wiki/Etiquette_(technology)

1 solution

i understand your problem....

you have to use double Data Type on the place of Integer

VB
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
ListBox1.Items.Add(TextBox1.Text)



Dim total As Double
For Each Str As String In ListBox1.Items
total = total + CDbl(Str)
Next

TextBox2.Text = total
End Sub
End Class


Now you can check your solution
 
Share this answer
 
Comments
Arjun Kerala 17-Aug-13 2:25am    
Rakesh Sir....Thank You So Much.I Used Your Code.......Now Working Fine...
Arjun Kerala 17-Aug-13 2:25am    
Thank You So Much
[no name] 17-Aug-13 2:42am    
its your pleasure dear..............

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900