VB 6.0 无法创建数组

VB 6.0 unable to create array

我无法在 VB 6.0 中创建数组,我正在疯狂地尝试解决这个问题。首先 VB 不是我的母语,我是一名 PHP 程序员,所以数组对我来说不是一个新概念......希望有人可以帮助解决这个问题。

这是我的功能:

Function get_plant() As String

Dim arrPlant(1 To 10) As String
arrPlant(1) = "PL1"
arrPlant(2) = "PL2"
arrPlant(3) = "PL3"
arrPlant(4) = "PL4"
arrPlant(5) = "PL5"
arrPlant(6) = "PL6"
arrPlant(7) = "PL7"
arrPlant(8) = "PL8"
arrPlant(9) = "PL9"
arrPlant(10) = "PL0"

get_plant = arrPlant

End Function

然后我尝试用这个调用它(以及大约 10 个其他变体...):

Dim plant_code() As String
plant_code = get_plant()
MsgBox plant_code(1)

当我尝试使用数组时,我得到了这个: Question mark in the array index

我到底错过了什么?

您提供的函数的 return 类型是 string 而不是 string() 并且您正在尝试 return 字符串数组。试试这个

Function get_plant() As String()