• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 556
  • Last Modified:

How can I use array in another array string?

Dear Experts,

I have a small question about array.
I have some code like this:

If n = 0 Then DataGridView.Rows.Add(u, objRemedyFieldName(0))
If n = 1 Then DataGridView.Rows.Add(u, objRemedyFieldName(0), objRemedyFieldName(1))
If n = 2 Then DataGridView.Rows.Add(u, objRemedyFieldName(0), objRemedyFieldName(1), objRemedyFieldName(2))
If n = 3 Then DataGridView.Rows.Add(u, objRemedyFieldName(0), objRemedyFieldName(1), objRemedyFieldName(2), objRemedyFieldName(3))
If n = 4 Then DataGridView.Rows.Add(u, objRemedyFieldName(0), objRemedyFieldName(1), objRemedyFieldName(2), objRemedyFieldName(3), objRemedyFieldName(4))
If n = 5 Then DataGridView.Rows.Add(u, objRemedyFieldName(0), objRemedyFieldName(1), objRemedyFieldName(2), objRemedyFieldName(3), objRemedyFieldName(4), objRemedyFieldName(5))
If n = 6 Then DataGridView.Rows.Add(u, objRemedyFieldName(0), objRemedyFieldName(1), objRemedyFieldName(2), objRemedyFieldName(3), objRemedyFieldName(4), objRemedyFieldName(5), objRemedyFieldName(6))
If n = 7 Then DataGridView.Rows.Add(u, objRemedyFieldName(0), objRemedyFieldName(1), objRemedyFieldName(2), objRemedyFieldName(3), objRemedyFieldName(4), objRemedyFieldName(5), objRemedyFieldName(6), objRemedyFieldName(7))
If n = 8 Then DataGridView.Rows.Add(u, objRemedyFieldName(0), objRemedyFieldName(1), objRemedyFieldName(2), objRemedyFieldName(3), objRemedyFieldName(4), objRemedyFieldName(5), objRemedyFieldName(6), objRemedyFieldName(7), objRemedyFieldName(8))
If n = 9 Then DataGridView.Rows.Add(u, objRemedyFieldName(0), objRemedyFieldName(1), objRemedyFieldName(2), objRemedyFieldName(3), objRemedyFieldName(4), objRemedyFieldName(5), objRemedyFieldName(6), objRemedyFieldName(7), objRemedyFieldName(8), objRemedyFieldName(9))
If n = 10 Then DataGridView.Rows.Add(u, objRemedyFieldName(0), objRemedyFieldName(1), objRemedyFieldName(2), objRemedyFieldName(3), objRemedyFieldName(4), objRemedyFieldName(5), objRemedyFieldName(6), objRemedyFieldName(7), objRemedyFieldName(8), objRemedyFieldName(9), objRemedyFieldName(10))
If n = 11 Then DataGridView.Rows.Add(u, objRemedyFieldName(0), objRemedyFieldName(1), objRemedyFieldName(2), objRemedyFieldName(3), objRemedyFieldName(4), objRemedyFieldName(5), objRemedyFieldName(6), objRemedyFieldName(7), objRemedyFieldName(8), objRemedyFieldName(9), objRemedyFieldName(10), objRemedyFieldName(11))
If n = 12 Then DataGridView.Rows.Add(u, objRemedyFieldName(0), objRemedyFieldName(1), objRemedyFieldName(2), objRemedyFieldName(3), objRemedyFieldName(4), objRemedyFieldName(5), objRemedyFieldName(6), objRemedyFieldName(7), objRemedyFieldName(8), objRemedyFieldName(9), objRemedyFieldName(10), objRemedyFieldName(11), objRemedyFieldName(12))
If n = 13 Then DataGridView.Rows.Add(u, objRemedyFieldName(0), objRemedyFieldName(1), objRemedyFieldName(2), objRemedyFieldName(3), objRemedyFieldName(4), objRemedyFieldName(5), objRemedyFieldName(6), objRemedyFieldName(7), objRemedyFieldName(8), objRemedyFieldName(9), objRemedyFieldName(10), objRemedyFieldName(11), objRemedyFieldName(12), objRemedyFieldName(13))
If n = 14 Then DataGridView.Rows.Add(u, objRemedyFieldName(0), objRemedyFieldName(1), objRemedyFieldName(2), objRemedyFieldName(3), objRemedyFieldName(4), objRemedyFieldName(5), objRemedyFieldName(6), objRemedyFieldName(7), objRemedyFieldName(8), objRemedyFieldName(9), objRemedyFieldName(10), objRemedyFieldName(11), objRemedyFieldName(12), objRemedyFieldName(13), objRemedyFieldName(14))
If n = 15 Then DataGridView.Rows.Add(u, objRemedyFieldName(0), objRemedyFieldName(1), objRemedyFieldName(2), objRemedyFieldName(3), objRemedyFieldName(4), objRemedyFieldName(5), objRemedyFieldName(6), objRemedyFieldName(7), objRemedyFieldName(8), objRemedyFieldName(9), objRemedyFieldName(10), objRemedyFieldName(11), objRemedyFieldName(12), objRemedyFieldName(13), objRemedyFieldName(14), objRemedyFieldName(15))
If n = 16 Then DataGridView.Rows.Add(u, objRemedyFieldName(0), objRemedyFieldName(1), objRemedyFieldName(2), objRemedyFieldName(3), objRemedyFieldName(4), objRemedyFieldName(5), objRemedyFieldName(6), objRemedyFieldName(7), objRemedyFieldName(8), objRemedyFieldName(9), objRemedyFieldName(10), objRemedyFieldName(11), objRemedyFieldName(12), objRemedyFieldName(13), objRemedyFieldName(14), objRemedyFieldName(15), objRemedyFieldName(16))
If n = 17 Then DataGridView.Rows.Add(u, objRemedyFieldName(0), objRemedyFieldName(1), objRemedyFieldName(2), objRemedyFieldName(3), objRemedyFieldName(4), objRemedyFieldName(5), objRemedyFieldName(6), objRemedyFieldName(7), objRemedyFieldName(8), objRemedyFieldName(9), objRemedyFieldName(10), objRemedyFieldName(11), objRemedyFieldName(12), objRemedyFieldName(13), objRemedyFieldName(14), objRemedyFieldName(15), objRemedyFieldName(16), objRemedyFieldName(17))
If n = 18 Then DataGridView.Rows.Add(u, objRemedyFieldName(0), objRemedyFieldName(1), objRemedyFieldName(2), objRemedyFieldName(3), objRemedyFieldName(4), objRemedyFieldName(5), objRemedyFieldName(6), objRemedyFieldName(7), objRemedyFieldName(8), objRemedyFieldName(9), objRemedyFieldName(10), objRemedyFieldName(11), objRemedyFieldName(12), objRemedyFieldName(13), objRemedyFieldName(14), objRemedyFieldName(15), objRemedyFieldName(16), objRemedyFieldName(17), objRemedyFieldName(18))
If n = 19 Then DataGridView.Rows.Add(u, objRemedyFieldName(0), objRemedyFieldName(1), objRemedyFieldName(2), objRemedyFieldName(3), objRemedyFieldName(4), objRemedyFieldName(5), objRemedyFieldName(6), objRemedyFieldName(7), objRemedyFieldName(8), objRemedyFieldName(9), objRemedyFieldName(10), objRemedyFieldName(11), objRemedyFieldName(12), objRemedyFieldName(13), objRemedyFieldName(14), objRemedyFieldName(15), objRemedyFieldName(16), objRemedyFieldName(17), objRemedyFieldName(18), objRemedyFieldID(19))
If n = 20 Then DataGridView.Rows.Add(u, objRemedyFieldName(0), objRemedyFieldName(1), objRemedyFieldName(2), objRemedyFieldName(3), objRemedyFieldName(4), objRemedyFieldName(5), objRemedyFieldName(6), objRemedyFieldName(7), objRemedyFieldName(8), objRemedyFieldName(9), objRemedyFieldName(10), objRemedyFieldName(11), objRemedyFieldName(12), objRemedyFieldName(13), objRemedyFieldName(14), objRemedyFieldName(15), objRemedyFieldName(16), objRemedyFieldName(17), objRemedyFieldName(18), objRemedyFieldID(19), objRemedyFieldID(20))

Open in new window


Is there any way to make it more streamline?
0
loginzhang
Asked:
loginzhang
1 Solution
 
Robert SchuttSoftware EngineerCommented:
This is one possible solution to make it shorter (but uses extra memory):
Dim objTemp(n + 1) As String
objTemp(0) = u
Array.Copy(objRemedyFieldName, 0, objTemp, 1, n + 1)
DataGridView.Rows.Add(objTemp)

Open in new window

0
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
You could also do:
        Dim data As New List(Of Object)
        data.Add(u)
        For i As Integer = 0 To n
            data.Add(objRemedyFieldName(i))
        Next
        DataGridView.Rows.Add(data.ToArray)

Open in new window

0
 
loginzhangAuthor Commented:
verified. works well. many thanks!
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now