Problem passing structure array to another function
Hello, all, wondering if someone can tell me what I'm doing wrong here. I'm simply trying to pass a structure array to another function for some evaluation. The problem is, it hits an error when I try to pass it. I'm using VB.NET 2003. Here is my code below.
VB Code:
Private Structure Fields
Dim FieldName As String
Dim FieldValue As String
End Structure
'In declarations section
Private Sub btnAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAdd.Click
Dim ArrValidate() As Fields
Dim cntrl As Control
Dim X As Long
'Fill my array
For Each cntrl In Me.Controls
X = X + 1
ReDim Preserve ArrValidate(X)
ArrValidate(X).FieldName = cntrl.Name
ArrValidate(X).FieldValue = cntrl.Text
Next cntrl
'Pass the array to my function located in another class
Validation.Validate_frmProducts(ArrValidate) 'Dies here
end sub
Error I get is:
Z:\HTTP\ProductMgmtApp\frmProducts.vb(576): Value of type 1-dimensional 'array of ManagementApp.frmProducts.Fields' cannot be converted to '1-dimensional array of System.Object' because 'ManagementApp.frmProducts.Fields' is not a reference type.
Anyone know what I'm doing wrong? Thanks in advance
Strick
Re: Problem passing structure array to another function
The error message is fairly explicit. The method argument is an Object array and you are passing a Fields array. There is no valid conversion between the two because Fields is a structure and therefore a value type. You will either need to make Fields a class so it is a reference type and the conversion is therefore valid, or else put your Fields objects in an Object array instead of a Fields array.