错误消息“使用新关键字创建对象实例”

发布于 2024-11-02 04:23:03 字数 953 浏览 4 评论 0原文

我一直在 ArrayGroup(count).dateDate = valueListString(0) 处收到错误消息,不知道下面的代码有什么问题,请帮忙。

Structure dataAttribute
    Dim dateDate As Date
    Dim timeString As String
    Dim volString As String
    Dim openString As String
    Dim closeString As String
    Dim minString As String
    Dim maxString As String
End Structure

Private ArrayGroup() As dataAttribute

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)     Handles Button1.Click
    Dim currencyString As String
    Dim valueListString() As String

    currencyString = dataTextFieldParser.ReadToEnd
    RichTextBox1.Text = currencyString

    strArr = currencyString.Split(Environment.NewLine)

    For count = 1 To strArr.Length - 1
        valueListString = strArr(count).Split(";")

        ArrayGroup(count).dateDate = valueListString(0)
        ArrayGroup(count).timeString = valueListString(1)
    Next


End Sub

I keep having error message at ArrayGroup(count).dateDate = valueListString(0), have no idea what's wrong with the code below, please help.

Structure dataAttribute
    Dim dateDate As Date
    Dim timeString As String
    Dim volString As String
    Dim openString As String
    Dim closeString As String
    Dim minString As String
    Dim maxString As String
End Structure

Private ArrayGroup() As dataAttribute

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)     Handles Button1.Click
    Dim currencyString As String
    Dim valueListString() As String

    currencyString = dataTextFieldParser.ReadToEnd
    RichTextBox1.Text = currencyString

    strArr = currencyString.Split(Environment.NewLine)

    For count = 1 To strArr.Length - 1
        valueListString = strArr(count).Split(";")

        ArrayGroup(count).dateDate = valueListString(0)
        ArrayGroup(count).timeString = valueListString(1)
    Next


End Sub

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

南烟 2024-11-09 04:23:03

ArrayGroupNothing

该行

Private ArrayGroup() As dataAttribute

不会为 ArrayGroup 赋值,因此它不会被实例化,当您尝试使用它时,您会收到正常的块错误。

您可能想将函数的结尾更改为类似的内容。

    Redim ArrayGroup(strArr.Length - 1) As dataAttribute


    For count = 1 To strArr.Length - 1
         valueListString = strArr(count).Split(";")

          ArrayGroup(count).dateDate = valueListString(0)         
          ArrayGroup(count).timeString = valueListString(1)     
    Next
End Sub 

请注意ReDim。我不确定您是否需要 As

ArrayGroup is Nothing.

the line

Private ArrayGroup() As dataAttribute

does not assign a value to ArrayGroup so it is not instantiated and you'll get the normal with block error when you try to use it.

you probably want to change the end of your function to something like.

    Redim ArrayGroup(strArr.Length - 1) As dataAttribute


    For count = 1 To strArr.Length - 1
         valueListString = strArr(count).Split(";")

          ArrayGroup(count).dateDate = valueListString(0)         
          ArrayGroup(count).timeString = valueListString(1)     
    Next
End Sub 

Note the ReDim. I'm not sure if you need the As.

不知在何时 2024-11-09 04:23:03

ArrayGroup 中可能确实有项目。

所以在行 ArrayGroup(count).dateDate = valueListString(0) 之前尝试添加到数组

ArrayGroup(count) = New ... what ever type should be in the array...

the ArrayGroup probably does actually have items in it.

so before the line ArrayGroup(count).dateDate = valueListString(0) try adding to the array

ArrayGroup(count) = New ... what ever type should be in the array...
最初的梦 2024-11-09 04:23:03

您似乎没有确定数组的尺寸:

尝试

ReDim ArrayGroup(0)

查看 ReDimReDim Preserve

Private ArrayGroup() As dataAttribute

只是声明 ArrayGroup 是一个 dataAttribute 类型的数组,但没有指定其中有多少个成员。

It does not appear that you have dimensioned you array:

Try

ReDim ArrayGroup(0)

Have a look at ReDim and ReDim Preserve

Private ArrayGroup() As dataAttribute

Just declares that ArrayGroup is an array of type dataAttribute but does not specify how many members are in it.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文