Array of TextBoxes

spke711

Member
Joined
Nov 29, 2006
Messages
12
Programming Experience
Beginner
Ok. I have an unfixed-length array of textboxes that I created globally:

VB.NET:
Dim CF_array() As TextBox

In one function, I used ReDim on the array to fix the length according to a local integer:

VB.NET:
Public Function function1()
    Dim someInt As Integer
    someInt = 4
 
    ReDim CF_array(someInt)
    'Then fill the array with textboxes and display on web form with Dynamic Controls
End Function

In another function, I need to get the values of the textboxes. Here's what I tried:

VB.NET:
Public Function function2()
    Dim CF_string As String
    Dim anInt As Integer
    anInt = 0
 
    CF_string = CF_array(anInt).Text
End Function

There seems to be a problem with "CF_string = CF_array(anInt).Text". I get the following error:

"System.NullReferenceException: Object reference not set to an instance of an object."

My guess is that when I ReDim and fill the array in the first function, it's not updating the global variable. So in the second function where I try to get values out of the global array, it's still empty. Any ideas? I think I'm on hour# 4 or 5 of trying to figure this out! Thanks in advance.
 
Page Load event (inherited from Control) is valid for all .Net versions. Maybe it's something with how you have declared the page/form. Try in codebehind to select your form object, then select its Load event, you might get an event handler like this:
VB.NET:
[SIZE=2][COLOR=#0000ff]Protected [/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Sub[/COLOR][/SIZE][SIZE=2] form1_Load([/SIZE][SIZE=2][COLOR=#0000ff]ByVal[/COLOR][/SIZE][SIZE=2] sender [/SIZE][SIZE=2][COLOR=#0000ff]As [/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Object[/COLOR][/SIZE][SIZE=2], [/SIZE][SIZE=2][COLOR=#0000ff]ByVal[/COLOR][/SIZE][SIZE=2] e [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] System.EventArgs) [/SIZE][SIZE=2][COLOR=#0000ff]Handles[/COLOR][/SIZE][SIZE=2] form1.Load[/SIZE]
 
[SIZE=2][COLOR=#0000ff]End [/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Sub[/COLOR][/SIZE]
 
is myBase.Load the same as Me.Load? all the webforms on my project seem to use myBase.Load for the Page_Load. I may be doing something wrong here....
 
I think I remember something about that difference between VS2003 and VS2005, yes, think it perhaps was only allowed mybase.load in ealier version - does it work for you with mybase.load for the page load event?
 
I don't get the compilation error when I use myBase.Load. I wouldn't say it's working though :p . I think I'm almost there....hopefully. Again, thanks to everybody for their help!
 
MyBase.Load is the 2003 way of doing it, Me.Load & form1.Load is the 2005 way of doing it, JohnH is starting to slip :p
 
Back
Top