Public Property MyArray() As String(,) Get End Get Set(ByVal Value As String(,)) End Set End Property |
Hello JMcilhinney
I made some modifications to the code you wrote for me. I took out the "," delimeter in the expressions because I'm working with arrays of rank 1. I believe the single "," makes the rank 2. I added a local variable because documentation on get procedure recommended that. In the following code an error ocorrs in the shaded violet color. The error says "Object reference not set to an instance of an object."
Module
Module1 Private local_array As Integer() Public Property array() As Integer() Get Return local_array End Get Set(ByVal value As Integer())local_array = value
End Set End Property Sub Main() Dim i As Integer = 0 For i = 1 To 10array(i) = 10 * i
Next End SubEnd
ModuleHowever, the issue isn't you property code. It's in the sub Main()
You have to redim your array before you can use it.
Sub Main() Dim i As Integer = 0 ReDim array(9) For i = 0 To array.GetUpperBound(0) array(i) = 10 * i Next End Sub |
I've changed your code for speed improvement. Dustin
You loop was from 1 to 10. Arrays start at base 0.
Redim Array(9) will create a 10 item array.
i changed For i = 0 To array.GetUpperBound(0)
becaue when you have a for/loop there's a small performance increase to use the .GetUpperBound(rank) function, as the compiler knows you will not change the dimensions of the array during the loop.
Hope this help!
hello Dustin
The program works fine with added code.
Thanks !
The reason for the property statements in the module are to allow me to access these arrays from any form in my application. I was told this was one way to do this.