Karzack Posted March 7, 2004 Posted March 7, 2004 Hello, Im new to programming in general. Did a little on apple IIE's but that wasn't much. I have desiced to try to learn again with vb.net and ran into something. I'm learning with the "Visual Basic .NET Step by Step" book. When I try to add a value to a variable in a structure I get an error. An unhandled exception of type 'System.NullReferenceException' Additional information: Object reference not set to an instance of an object. Example: Trying to make a small address book. This structure and the sub are in the module. frmAdd is the form that information is added to the address book. Structure Person Public firstName As String Public middleName As String Public lastName As String Public homeNumber As String Public email As String Public address As String Public city As String Public state As String Public workNumber As String Public cellNumber As String Public photo As Image End Structure Public page() As Person ' Array for number of people in book Public pg As Short ' value to determine how many pages Sub pageFill() page(pg).firstName = frmAdd.txtFirstName.Text ' < error here page(pg).middleName = frmAdd.txtMiddleName.Text page(pg).lastName = frmAdd.txtLastName.Text page(pg).homeNumber = frmAdd.txtHomeNumber.Text end sub Didn't put in the rest of the sub because it was the same as the first few lines. Anyway. When I type in the values in the text boxes and hit the button that calles this sub. I get the error described above. At the first line of the sub. I think I need to back off coding for now, I have a headache. :( I have done some tread searching but didn't come up with anything. Quote
MikeJ Posted March 7, 2004 Posted March 7, 2004 It doesn't appear as if you have told the program what pg is or how many items the array will hold. Is there any other part of this code, such as a ReDim statement, or where you are setting the variable pg? If not, before you are able to get to the array, you will need to ReDim it to let it hold a certain number of elements, and then you will need to define pg with a value to access the particular part of the array. Quote
Karzack Posted March 8, 2004 Author Posted March 8, 2004 *sighs* I just forgot to redim the array. :o Thank you. Value for pg was set before sub was called. *muddles under his breath* Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.