0

I have made researched but none of them related to my question in VB.net. I don't know why after calling to other subs, they don't return to the original caller in Form_Load()

In the form_load, I call this sub:

 Public Sub frm1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
For i As Integer = 0 To dt.Rows.Count - 1       
         Call calculateCounts(dt.Rows(i).Item(0))     'call sub and pass the parameter

    Next
End Sub

Public Sub calculateCounts(ByVal st as string)
'In this sub, I calculate the counts for a 2D array and pass it to another sub     procedure
     DisplayData(aryRow, st)
End sub

Public DisplayData(ByRef aryRow(,) as integer, ByVal st as string)
     'This sub display data
End Sub

After it runs through the first time, display data correctly for the "st" parameter, it doesn't return to the original caller (form_load) to proceed to the next row. Do you know what is wrong here and what is the alternative way to fix it? thank you in advance for your help.

user3754205
  • 27
  • 1
  • 6
  • if `aryRow` is uninitilized - we cant see that it is - you could be encountering a NullReference exception. Move your Form_load code to a button click and see what happens (diagnostic); maybe set a breakpoint to be sure it *isnt* returning – Ňɏssa Pøngjǣrdenlarp Nov 07 '14 at 16:43
  • 1
    This is probably a mix of **[What is a NullReferenceException and how do I fix it?](http://stackoverflow.com/questions/4660142/what-is-a-nullreferenceexception-and-how-do-i-fix-it)** and **[Why the form load can't catch exception?](http://stackoverflow.com/questions/3209706/why-the-form-load-cant-catch-exception)**. – Bjørn-Roger Kringsjå Nov 07 '14 at 16:49
  • Plutonix and Bjorn-Roger are correct. I have NullReference exception because I declare the aryRow(,) outside the loop without initializing it. Redim indise the loop and reuse outside it. Array trouble! I have to change to List (of Integer). It's new to me, though – user3754205 Nov 07 '14 at 18:58

0 Answers0