Arrays Visual Basic数组

Arrays Visual Basic数组,arrays,vb.net,basic,Arrays,Vb.net,Basic,您好,我在visual basic中使用数组时遇到了困难。这是一个简单的控制台应用程序(在我转到gui之前,我正在尝试掌握语法的诀窍),这个程序所做的就是使用两种类型的数组:交错数组和常规数组。此控制台应用程序是一个时间表生成器,即输入5列5行以生成5X5时间表。该程序还没有完成,我知道时间表不会生成与此代码到目前为止,但我需要的帮助是如何在VB中填充数组。我的问题出在这艘潜艇上 分: 具体地说,行regulararay(j,i)=mult我认为这很简单,数组元素被设置为=mult的值,for循

您好,我在visual basic中使用数组时遇到了困难。这是一个简单的控制台应用程序(在我转到gui之前,我正在尝试掌握语法的诀窍),这个程序所做的就是使用两种类型的数组:交错数组和常规数组。此控制台应用程序是一个时间表生成器,即输入5列5行以生成5X5时间表。该程序还没有完成,我知道时间表不会生成与此代码到目前为止,但我需要的帮助是如何在VB中填充数组。我的问题出在这艘潜艇上

分:

具体地说,行
regulararay(j,i)=mult
我认为这很简单,数组元素被设置为
=
mult的值,for循环将覆盖2d数组。我做错了什么?我怎样才能修复它或做得更好

完整代码:

 Module Module1
    Sub Main()
        'Declarations
        Dim awns As Char
        Dim switchOption As Integer
        Dim columns As Integer
        Dim rows As Integer
        Dim regularArray(columns, rows) As Integer 

        'Starting Prompts
        Console.WriteLine("Hello this program will create a times table with")
        Console.WriteLine("user inputs in terms of rows and columns.")
        Console.WriteLine("Pick between these two options.")
        Console.WriteLine("Option 1: Times table with a regular array.")
        Console.WriteLine("Option 2: Times table with a jagged array.")

        Do
            Console.Write("Which option do you wnat? ")
            switchOption = Console.ReadLine

            Console.WriteLine("How many columns do you wnat? ")
            columns = Console.ReadLine
            columns = columns - 1
            Console.WriteLine("How many rows do you wnat? ")
            rows = Console.ReadLine
            rows = rows - 1
            Select Case switchOption
                Case 1
                    arrayPopulate(regularArray, columns, rows)
                    Dim i As Integer
                    Dim j As Integer

                    For j = 0 To rows
                        For i = 0 To columns
                            Console.WriteLine("{0}: ", regularArray(i, j))
                        Next
                    Next

                Case 2
                    Console.WriteLine("Test")

            End Select

            Console.WriteLine("Do you want to run again y/n?")
            awns = Console.ReadLine()
        Loop Until awns = "n"
    End Sub

    Sub arrayPopulate(ByVal regularArray(,) As Integer, ByVal columns As Integer, ByVal rows As Integer)
        Dim i As Integer
        Dim j As Integer
        Dim mult As Integer

        For i = 0 To rows
            For j = 0 To columns
                mult = (i + 1) * (j + 1)
                regularArray(j, i) = mult
            Next
        Next

    End Sub
End Module

如果将
Dim regularArray(列、行)声明为整数
,它将使用
的值,就像它们当时一样;在本例中,它们都是零,因此
regularray
是一个具有一个元素的二维数组,即
regularray(0,0)
。使用
ReDim
更改其尺寸的大小。例如,将其置于
选择案例切换选项之前:

ReDim regularArray(columns, rows)

有关详细信息,请参见。

当您将
Dim REQUALARRAY(列、行)声明为Integer
时,它将使用
的值;在本例中,它们都是零,因此
regularray
是一个具有一个元素的二维数组,即
regularray(0,0)
。使用
ReDim
更改其尺寸的大小。例如,将其置于
选择案例切换选项之前:

ReDim regularArray(columns, rows)
有关详细信息,请参阅