Click here to Skip to main content
16,013,918 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i wanted to add these two arays and get result in textbox3.
But the values are not getting added... they are getting double/...
plz help me.....




  Dim value(,) As Double = New Double(,) {{1, 2}, {3, 4}, {5, 6}, {44, 66}}
        Dim value2(,) As Double = New Double(,) {{11, 2}, {31, 4}, {51, 6}, {44, 66}}

        For i As Integer = 0 To UBound(value, 1)
            TextBox1.Text &= String.Format("{0}{1}{2}", value(i, 0).ToString.PadLeft(10), value(i, 1).ToString.PadLeft(10), vbNewLine)
            TextBox2.Text &= String.Format("{0}{1}{2}", value2(i, 0).ToString.PadLeft(10), value(i, 1).ToString.PadLeft(10), vbNewLine)

        Next
textbox3.text=textbox1+textbox2

    End Sub
Posted

1 solution

What do you expect to happen here?
It adds no number together.
All it does is convert each array of doubles to a string, then concatenate the two strings together.

If you want this to add two arrays of values together, then you need to add the values, not convert them to strings. For example:
VB
Dim value As Double(,) = New Double(,) {{1, 2}, {3, 4}, {5, 6}, {44, 66}}
Dim value2 As Double(,) = New Double(,) {{11, 2}, {31, 4}, {51, 6}, {44, 66}}
Dim outp As Double(,) = New Double(3, 1) {}
For i As Integer = 0 To value.GetUpperBound(0)
    For j As Integer = 0 To value.GetUpperBound(1)
        outp(i, j) = value(i, j) + value2(i, j)
    Next
Next
 
Share this answer
 
Comments
arizan 29-Jun-12 2:19am    
hey thanx but getting result as -
12 0
12 4
34 0
34 8
56 0
56 12
88 0
88 132
arizan 29-Jun-12 2:30am    
i want the result as
12 4
34 8
56 12
88 132

please tell what changes should be done...
OriginalGriff 29-Jun-12 2:34am    
That is because you are trying to use the results as they are generated.
Start looking at what is going on, and thinking about it.
Then you can apply it to your task.

That has two loops: the inner loop adds each element of each column of a row, and the outer loop goes though each row.
If you want to use a row worth of results, where should you put your code?
arizan 29-Jun-12 2:46am    
hey now i have displayed result in textbox3 as
For j As Integer = 0 To value.GetUpperBound(1)
outp(i, j) = value(i, j) + value2(i, j)
textbox3.text= outp(i,j)
Next

getting result as only 132
sorry but i am new in vb.net
plz help....
OriginalGriff 29-Jun-12 3:08am    
When I said "thinking about it" did you assume I was joking? :laugh:
textbox3.Text = outp(i,j)
What do you think this does in a loop? what value does it have after the loop is over?
Think about what you are trying to achieve (which I have no idea about) and look at what you have. Where is the data you want? (What is the data you want!)?

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