开发者

Error Message "Use The New Keyword To Create An Object Instance"

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


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.


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...


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜