Results 1 to 3 of 3

Thread: Problem retrieving value from an array of string [Resolved]

  1. #1

    Thread Starter
    Registered User
    Join Date
    Apr 2003
    Location
    Klang, Selangor, Malaysia
    Posts
    163

    Question Problem retrieving value from an array of string [Resolved]

    I have this problem when retrieving value from an array of string.

    this is my code:
    Code:
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
            Dim strSplitted() As String = funSplitText(txtRinggit.Text)
            MessageBox.Show(strSplitted.Length)
            Dim intCounter As Integer
            For intCounter = 0 To strSplitted.GetUpperBound(0)
                MessageBox.Show(strSplitted(intCounter).ToString)
            Next
        End Sub
    When Button1 is clicked, the length of strSplitted can be display correctly.
    But the error oocurs inside the For...Next Statement in this line:
    Code:
    MessageBox.Show(strSplitted(intCounter).ToString)
    The error message shows:
    An unhandled exception of type 'System.NullReferenceException' occurred in Payroll System.exe.

    Additional information: Object reference not set to an instance of an object.
    Why is this so? it seem to retrieve the length of the array without problem, but has problem retrieving each value inside array.

    How can i overcome this problem? please guide. thank you.
    Last edited by albertlse; Aug 21st, 2003 at 08:11 PM.

  2. #2
    Member
    Join Date
    Jul 2003
    Location
    Sweden
    Posts
    62
    try

    For intCounter = 0 To strSplitted.Lenght-1

    instead of
    For intCounter = 0 To strSplitted.GetUpperBound(0)

    Since the array starts in 0.
    example
    H e l l o
    0,1,2,3,4
    = 5 chars
    //Martin Andersson

  3. #3

    Thread Starter
    Registered User
    Join Date
    Apr 2003
    Location
    Klang, Selangor, Malaysia
    Posts
    163
    i had found the solution:
    add the word "Preserve" after "ReDim"

    anyway, thanx Iceman5

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width