Quantcast
Channel: VBForums - Visual Basic .NET
Viewing all articles
Browse latest Browse all 27349

Array error - array of 2-dimensional cannot be converted to integer

$
0
0
Hello there,

I had a datatable with these colums: idSupplier, Item and Price. I wish to return the sum of the Items for each idSuplier, and display which has the lowest price, highest price and the order among then. So, I was thinking in using a sorted Array, and then bring the information through labels, like: "The lowest price of the list is from "@idsuplier@", with the amount of "@; the highest price is from "@idspuplier@"...and the others are...

An example of my table would be:

idSuplier Item Price
1 Item A 10.00
1 Item B 20.00
1 Item C 30.00
2 Item A 20.00
2 Item B 30.00
2 Item C 40.00
3 Item A 30.00
3 Item B 40.00
3 Item C 50.00

So the desired result would be : (1, 60.00); (2, 90.00) and (3, 120.00)

I tried the following code:


Code:

Imports System.Data.SqlClient
Imports System.Data
'Imports System.Collections.Generic
'Imports System.Collections.CollectionBase



Public Class suppliers

    Public Shared j As Integer
    'Public valuei As Integer
    Public i As Integer = 1
    Private WithEvents myDataGridView As New DataGridView
    'Public myArray(i) As Integer
    Public myArray(i,i) As Integer



private sub array ()


Dim value As Integer
'ReDim myArray(j)

ReDim myArray(j, j) *\ j represents the number of suppliers
       
        For i = 1 To j
            For Each col As DataGridViewRow In dgItems.Rows
                If col.Cells(0).Value = i Then
                   

                    'myArray(i) = myArray(i) + CInt(col.Cells(2).Value)

                    value = value + CInt(col.Cells(2).Value)

                    myArray(i, i) = {{value}, {i}} ' here I got an error "Value of type '2-dimensional array of integer' cannot be converted to integer

 

                End If


            Next
           
        Next i
       
        show()

    End Sub


private sub show()


sortlist() ' sub to sort the itens

For i = 1 To j

            MsgBox(myArray(i), i) 'It doesnt work for a 2 dimensional array
            'MsgBox(myArray(i))
     
          Next
end sub


Private Sub btnFind_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnFind.Click

array()

end sub

Well done! But I can't add the "i" which would brought the idsupplier...please, anyone could help me with this error?

Viewing all articles
Browse latest Browse all 27349

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>