G
Guest
Hi
I am trying to use an array in my vb.net windows appliaction but i keep encountering an error
This is what i have done so far
I have declared 2 arrays and 1 varible (to keep track of the index position
Public MyMealTypeArray() As Strin
Public MyMealQtyArray() As Intege
Public ArrayIndex As Integer =
I then add values to my array in an onclick event of a button
'if the items are not empty push the data to my array
If Not ((CBoxMealName.Text = "") Or (txtMealQty.Text = "")) The
MyMealTypeArray(ArrayIndex) = CBoxMealName.Tex
MyMealQtyArray(ArrayIndex) = txtMealQty.Tex
'increment the arrayInde
ArrayIndex = ArrayIndex +
Els
'else display a message to state all required field are neede
MsgBox("Please ensure all the required fields are entered correctly"
End I
Once all the data has been gathered, i then try to push the data that is in my arrays into a datatable
Dim MealInsRow As DataRo
For ArrayIndex = 0 To ArrayInde
MealInsRow = dsFullBooking.Tables("dtMealBooking").NewRow(
MealInsRow("BookingNo") = "-1
MealInsRow("RoomID") = RoomI
MealInsRow("RoomDt") = dtpRoomDate.Tex
MealInsRow("Req_Session") = CBoxSession.Tex
MealInsRow("Meal_Type") = CBoxMealName.Tex
MealInsRow("Meal_Qty") = txtMealQty.Tex
'Add the new record to the table by calling the Add method of the DataRowCollection object.
dsFullBooking.Tables("dtMealBooking").Rows.Add(MealInsRow
Next ArrayInde
This is the error that i get
An unhandled exception of type 'System.NullReferenceException' occurred in Caravan.ex
Additional information: Object reference not set to an instance of an object
My application stops at this line
MyMealTypeArray(ArrayIndex) = CBoxMealName.Tex
Can anyone see where i am going wrong
Any help would be great
Thank
I am trying to use an array in my vb.net windows appliaction but i keep encountering an error
This is what i have done so far
I have declared 2 arrays and 1 varible (to keep track of the index position
Public MyMealTypeArray() As Strin
Public MyMealQtyArray() As Intege
Public ArrayIndex As Integer =
I then add values to my array in an onclick event of a button
'if the items are not empty push the data to my array
If Not ((CBoxMealName.Text = "") Or (txtMealQty.Text = "")) The
MyMealTypeArray(ArrayIndex) = CBoxMealName.Tex
MyMealQtyArray(ArrayIndex) = txtMealQty.Tex
'increment the arrayInde
ArrayIndex = ArrayIndex +
Els
'else display a message to state all required field are neede
MsgBox("Please ensure all the required fields are entered correctly"
End I
Once all the data has been gathered, i then try to push the data that is in my arrays into a datatable
Dim MealInsRow As DataRo
For ArrayIndex = 0 To ArrayInde
MealInsRow = dsFullBooking.Tables("dtMealBooking").NewRow(
MealInsRow("BookingNo") = "-1
MealInsRow("RoomID") = RoomI
MealInsRow("RoomDt") = dtpRoomDate.Tex
MealInsRow("Req_Session") = CBoxSession.Tex
MealInsRow("Meal_Type") = CBoxMealName.Tex
MealInsRow("Meal_Qty") = txtMealQty.Tex
'Add the new record to the table by calling the Add method of the DataRowCollection object.
dsFullBooking.Tables("dtMealBooking").Rows.Add(MealInsRow
Next ArrayInde
This is the error that i get
An unhandled exception of type 'System.NullReferenceException' occurred in Caravan.ex
Additional information: Object reference not set to an instance of an object
My application stops at this line
MyMealTypeArray(ArrayIndex) = CBoxMealName.Tex
Can anyone see where i am going wrong
Any help would be great
Thank