【问题标题】:VB6 Split string into an array Error "Can't assign into array" compile errorVB6将字符串拆分为数组错误“无法分配到数组”编译错误
【发布时间】:2021-07-21 18:03:41
【问题描述】:

我正在尝试在 VB6 中将字符串拆分为数组。

字符串存储在数据库中,如下所示:

“按价值:”

有时它可能在冒号后的末尾包含更多内容,这就是为什么我想在 if 语句中比较它时将其拆分,如下所示。

总的来说,我的代码是这样的:

Dim deliveryType(2) As String

deliveryType = Split(vaGoodsInLine.FieldValue("Comment"), ":")

If deliveryType(0) = "By Value " Then
 'Do Something
End IF

我收到以下错误

我还尝试将数组定义为没有大小的变体:

Public deliveryType() As Variant

但是我得到了这个错误

【问题讨论】:

  • @GSerg 很遗憾没有,我收到运行时错误“13”类型不匹配
  • 如果您已将 deliveryType 重新声明为 Variant,那么您不应该这样做。你应该有removed the fixed size
  • 这里有很多错误。这只是开始。
  • 不要在数组上设置大小...Dim deliveryType(2) As String 应该只是Dim deliveryType() As String。那么原版应该没问题。第二个,你可以试试Dim deliveryType As Variant,不带()s,因为Variant已经可以接受数组和非数组了。

标签: arrays vb6


【解决方案1】:
Dim deliveryType() As String
deliveryType = Split(vaGoodsInLine.FieldValue("Comment"), ":")
Dim deliveryTypeValue As String

If Not UBound(deliveryType) = 0 Then
    deliveryTypeValue = NullStr(deliveryType(0))
End If
    
If deliveryTypeValue = "By Value" Then
    'Do Something
End IF

这对我有用。

【讨论】:

  • 你的前 2 行合并成一个了吗?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2014-10-01
  • 1970-01-01
  • 2021-07-06
  • 1970-01-01
  • 1970-01-01
  • 2016-04-01
  • 1970-01-01
相关资源
最近更新 更多