[英]Visual Basic Initialize Array Error
The goal of my program is to initialize a one-dimensional array through calling a sub-procedure in the main procedure. 我程序的目标是通过在主过程中调用子过程来初始化一维数组。 I get an error, though, on "TestScores" in my initializing for loop that the expression is not an array or method. 但是,在初始化for循环的“ TestScores”上出现错误,表示表达式不是数组或方法。 I have it declared in the main function that TestScores is an array with an upper-bound of 10. What am I doing wrong? 我在主函数中声明TestScores是一个上限为10的数组。我在做什么错?
'Author: Michael Barney
Option Explicit On
Option Strict On
Module Module1
Sub Main()
Dim Index As Integer
Dim TestScores(10) As Double
InitializeArray(TestScores)
PrintArray(TestScores)
LoadArray(TestScores)
PrintArray(TestScores)
SearchArray(TestScores)
End Sub
Sub InitializeArray(ByRef TestScores As Double)
Console.WriteLine("Entering: -----------------------> InitializeArray")
Dim Index As Integer
For Index = 0 To 10
TestScores(Index) = 0.0
Next Index
Console.WriteLine("Exiting: -----------------------> InitializeArray")
End Sub
Sub PrintArray(ByVal TestScores As Double)
Console.WriteLine("Entering: -----------------------> PrintArray")
'Your code goes here...
Console.WriteLine("Exiting: -----------------------> PrintArray")
End Sub
Sub LoadArray(ByVal TestScores As Double)
Console.WriteLine("Entering: -----------------------> LoadArray")
'Your code goes here...
Console.WriteLine("Exiting: -----------------------> LoadArray")
End Sub
Sub SearchArray(ByVal TestScores As Double)
Console.WriteLine("Entering: -----------------------> SearchArray")
'Your code goes here...
Console.WriteLine("Exiting: -----------------------> SearchArray")
End Sub
End Module
You're method is taking TestScores as a Double, not as an array of Doubles. 您的方法是将TestScores视为Double,而不是Doubles数组。
Sub InitializeArray(ByRef TestScores As Double)
Should be 应该
Sub InitializeArray(ByRef TestScores() As Double)
This change will also need to be made to all your other subs as well. 还需要对所有其他子项进行此更改。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.