|
-
Aug 13th, 2003, 10:18 PM
#1
Thread Starter
Registered User
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.
-
Aug 14th, 2003, 03:38 AM
#2
Member
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
-
Aug 14th, 2003, 04:25 AM
#3
Thread Starter
Registered User
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|