类型不匹配在ASP数组赋值 [英] Type mismatch on an Array assignment in ASP

查看:88
本文介绍了类型不匹配在ASP数组赋值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

它已经有一段时间,因为我已经与ASP的工作,但我得到什么似乎是一个简单的赋值语句类型不匹配错误。任何人都可以解释为什么这可能发生的一些情况。

Its been a while since I've worked with ASP, but I'm getting a Type mismatch error on what seems to be a simple assignment statement. Can anyone shed some light on why this might be happening.

这个工作,但是当我尝试的foreach未分配问题阻止我得到一个对象不是一个集合错误

This works, but when I try to foreach an unassigned Questions block I get an Object not a collection error

Class Survey
  public ID
  public Title
  public Questions
End Class

Sub Test()
  Dim oSurvey
  Set oSurvey = new Survey
  Dim aQuestions(2)
  Set aQuestions(0) = new Question
  ' Other aQuestions assignments
  oSurvey.Questions = aQuestions
End Sub

另外如果我设置问题作为一个动态数组,然后分配失败,类型不匹配错误。

Alternately If I setup questions as a dynamic array then the assignment fails with a type mismatch error.

Class Survey
  public ID
  public Title
  public Questions()
End Class

Sub Test()
  Dim oSurvey
  Set oSurvey = new Survey
  Dim aQuestions(2)
  Set aQuestions(0) = new Question
  ' Other aQuestions assignments
  ' Throws a Type mismatch error here
  oSurvey.Questions = aQuestions
End Sub

有什么想法?

推荐答案

所以,我结束了数组声明坚持。此外,当我试图REDIM阵列,像这样我得到了一个错误。

So I ended up sticking with the Array declaration. Additionally, When I tried to ReDim the array like so I got an error.

ReDim oSurvey.Questions(2)

所以我创建了一个子例程REDIM该数组,这个工作。

So I created a sub routine to ReDim the Array, and this worked.

Class Survey
  public ID
  public Title
  public Questions()

  sub ReDimQuestions(count)
    ReDim Questions(count)
  end sub
End Class

Sub Test()
  Dim oSurvey
  Set oSurvey = new Survey
  oSurvey.ReDimQuestions 2
  Set oSurvey.Questions(0) = new Question
  ' Other aQuestions assignments
End Sub

这篇关于类型不匹配在ASP数组赋值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆