Array Function

D

Darkman

Hi,

I am wondering how you multi-dimension an array function?

My declared function looks like this:

Public Function GetCustomerList(ByVal Val1 As String, ByVal Val2 As Long,
ByVal Val3 As String) As String()

Previously I dimensioned a single dimension Array to the size I wanted and
then just set the value of my function from this new Array.

Now I need to set a multi-dimension Array because I am reading more than one
record into the Array.

When I try to set the value of my function with the new muti-dimension Array
I get an error:

Value of type '2-dimensional array of String' cannot be converted to
'1-dimensional array of String' because the array types have different
numbers of dimensions.

Can anyone please provide assistance as to how to multi-dimension the
Function Array while still having the input parameters.

Thanks
 
T

Tom Shelton

Hi,

I am wondering how you multi-dimension an array function?

My declared function looks like this:

Public Function GetCustomerList( _
ByVal Val1 As String, _
ByVal Val2 As Long, _
ByVal Val3 As String) As String(,)

HTH
 
C

Cor Ligthert[MVP]

Darkman,

You should not want to do this in 2008, in version 2005 there was already
the Generic List, which makes working with multidimensional arrays (lists)
much easier for you.

Cor
 
T

Tom Shelton

Darkman,

You should not want to do this in 2008, in version 2005 there was already
the Generic List, which makes working with multidimensional arrays (lists)
much easier for you.

Cor

"Darkman" <[email protected]> schreef in bericht












- Show quoted text -

Re-reading the what the OP said, I agree... I think this would be
more along the lines of something like:

Public Function GetCustomerList( _
ByVal Val1 As String, _
ByVal Val2 As Long, _
ByVal Val3 As String) As List(Of Customer)

Where customer is a custom buisness object containing the "record"
data.
 
A

Armin Zingler

Darkman said:
Hi,

I am wondering how you multi-dimension an array function?

My declared function looks like this:

Public Function GetCustomerList(ByVal Val1 As String, ByVal Val2 As
Long, ByVal Val3 As String) As String()

Previously I dimensioned a single dimension Array to the size I
wanted and then just set the value of my function from this new
Array.

Now I need to set a multi-dimension Array because I am reading more
than one record into the Array.

When I try to set the value of my function with the new
muti-dimension Array I get an error:

Value of type '2-dimensional array of String' cannot be converted to
'1-dimensional array of String' because the array types have
different numbers of dimensions.

Can anyone please provide assistance as to how to multi-dimension
the Function Array while still having the input parameters.

I'm not sure what you want. Which statement gives the error? What's the
declaration of the involved variables?


Armin
 
D

Darkman

Let me explain further..

I have a DLL which I use to interact with the database. In the same project
I have a vb.net 2005 application which calls the DLL.

By adding the (,) as string the function in the DLL now compiles correctly.
However when I rebuild the DLL the function is not visible.

I have no idea about how to create a custom business object. This
application will never be upgraded to .net 2008 and I just need a quick fix.

Thanks
 
K

kimiraikkonen

Let me explain further..

I have a DLL which I use to interact with the database. In the same project
I have a vb.net 2005 application which calls the DLL.

By adding the (,) as string the function in the DLL now compiles correctly.
However when I rebuild the DLL the function is not visible.

I have no idea about how to create a custom business object. This
application will never be upgraded to .net 2008 and I just need a quick fix.

Thanks

IIUC, you cannot see dll's function under your exe project. Right?
IMHO, the following reasons may cause this:

1-Incorrect usage of "imports" statement. Use imports for importing
correct library, namaespace.
(eg: imports system.text) and Use imports statement at the top of your
exe project code page. Even before, "Public Class".
2-Have referenced your library to your project? Right click -> add
reference?
3-Always use "public" instead of private or else like you did.

I hope you solve the problem.

Hope this helps.
 
D

Darkman

I can see my other functions within the DLL just fine.

I have declared this function as public.

It's only since adding the (,) As String in place of () As String that the
problem has occured:

Public Function GetCustomerList(ByVal Val1 As String, ByVal Val2 As Long) As
String(,)

Public Function GetCustomerList(ByVal Val1 As String, ByVal Val2 As Long) As
String()
 
K

kimiraikkonen

I can see my other functions within the DLL just fine.

I have declared this function as public.

It's only since adding the (,) As String in place of () As String that the
problem has occured:

Public Function GetCustomerList(ByVal Val1 As String, ByVal Val2 As Long) As
String(,)

Public Function GetCustomerList(ByVal Val1 As String, ByVal Val2 As Long) As
String()

What does your function return with val1 and val2?

Here is an assumption:

I simulated something and assumed val1 is a customer name and val2 is
and customer ID (just an assumption, you didn't specified because).

Create a new form named "form1" and add these into your form:
(Here is customer name is "xyz" and "id" is 5000 as sample.)

Imports ClassLibrary1
Public Class Form1

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Dim customers As New customerlist
MsgBox(customers.GetCustomerList("xyz ", 5000))

End Sub
End Class

Then add a class library into your project by going through file ->
add -> new project -> class library. Then reference the library by
right click -> add reference -> projects -> your library name (i'd
suggest you to name your library as "Classlibrary1" in this sample).

Then put these into your library:

Option Explicit On

Public Class customerlist

Public Function GetCustomerList(ByVal Val1 As String, ByVal Val2
As Long) As String
Return Val1 & Val2
End Function
End Class

You should be able to get an result on form load inside a message box
as function returns customer name & ID.

Remember this sample was just an assumption and it depends on your
desire of course you can add another function returns.

Hope this helps.
 
D

Darkman

Let me clarify.

I already have a function in the DLL called:

Public Function GetCustomer(ByVal Val1 As String, ByVal Val2 As Long) As
String()

This is a single dimension Array as it only returns the record for a single
customer. I can reference this function from the DLL fine.

I have a second function in the DLL called:

Public Function GetCustomerList(ByVal Val1 As String, ByVal Val2 As Long) As
String(,)

This is a multi-dimension Array because it returns multiple records. I
cannot see this function when I reference the Array. However if I remove the
"," which declares the function as a multi-dimension I CAN see the function
when I reference the DLL. (i.e.)

Public Function GetCustomerList(ByVal Val1 As String, ByVal Val2 As Long) As
String()
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top