3

I cannot find an easy way to assign values to a multidimensional array. It works like this:

Dim tTableArray(2, 14) As String
tTableArray(0, 0) = "John"
tTableArray(1, 0) = "Doe"

but it seems like I should be able to do something like this:

Dim tTableArray(2, 14) As String
tTableArray({0, 1}, 0) = {"John", "Doe"}

It seems like there aught to be way to do that, because when you are defining the array you can, for example:

Dim values(,) As String = New String(,) {{"John", "Doe"}, {"Jane", "Doe"}, {"Spot", "the Dog"}}

Any Ideas? Sorry, first questions - still need to figure out how to make a code block look like code.

Thanks, Chris

1 Answer 1

2

I don't know of a built-in way to assign that, however a self-made sub might be just as good. An extension suggestion:

Imports System.Runtime.CompilerServices  
Module Module1

    <Extension()>
    Public Sub setRow(p(,) As Object, pRow As Integer, pValues As Object())
        If p.GetLength(1) >= pValues.Length Then
            For i As Integer = 0 To pValues.Length - 1
                p(pRow, i) = pValues(i)
            Next
        End If
    End Sub

End Module

Usage:

    Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
        Dim x(,) As String
        ReDim x(2, 4)

        x.setRow(0, {"Mr.", "", "John", "Doe", "-"})
        x.setRow(1, {"Ms.", "Dr.", "Sue", "Smith", "-"})
        ' ...
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.