473,403 Members | 2,071 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,403 software developers and data experts.

Arrays

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(Mea lInsRow
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

Jul 21 '05 #1
6 1550
Cor
Hi Eva, Ar,, ... Bhavna,

I have seen this booking thing with every woman name there is on the world I
think.

:-))

I had a solution, but what is the sence of this operation, you do not need
the array I think in the way you describe it now.

There is a dataset.rejectchanges did you know?

Have a look for that.

But maybe I mis something.

Cor
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 String
Public MyMealQtyArray() As Integer
Public ArrayIndex As Integer = 0

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 = "")) Then
MyMealTypeArray(ArrayIndex) = CBoxMealName.Text
MyMealQtyArray(ArrayIndex) = txtMealQty.Text

'increment the arrayIndex
ArrayIndex = ArrayIndex + 1
Else
'else display a message to state all required field are needed
MsgBox("Please ensure all the required fields are entered correctly") End If
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 DataRow

For ArrayIndex = 0 To ArrayIndex
MealInsRow = dsFullBooking.Tables("dtMealBooking").NewRow() MealInsRow("BookingNo") = "-1"
MealInsRow("RoomID") = RoomID
MealInsRow("RoomDt") = dtpRoomDate.Text
MealInsRow("Req_Session") = CBoxSession.Text
MealInsRow("Meal_Type") = CBoxMealName.Text
MealInsRow("Meal_Qty") = txtMealQty.Text
'Add the new record to the table by calling the Add method of the DataRowCollection object. dsFullBooking.Tables("dtMealBooking").Rows.Add(Mea lInsRow)
Next ArrayIndex
This is the error that i get:
An unhandled exception of type 'System.NullReferenceException' occurred in Caravan.exe Additional information: Object reference not set to an instance of an object.
My application stops at this line:
MyMealTypeArray(ArrayIndex) = CBoxMealName.Text

Can anyone see where i am going wrong?
Any help would be great.
Thanks

Jul 21 '05 #2
Hello Cor

This is the way i have been forced to do it as i cannot add these values to my datatable until the data has been added to my parent table first (referential integrity). As the data to my parent table cannot be added until later i have chose to add the child tables data into a array until the right time

Can u help me for gettin this array to work
I know of this other person. This is a school project so i guess everyone has latched onto this site for help. :o
Jul 21 '05 #3
You can fix this probelm By:

1. Gave those arrays a size
Public MyMealTypeArray(50) As String
Public MyMealQtyArray(50) As Integer

or

2. use arrayList

Public MyMealTypeArray as arrayList
Public MyMealQtyArray As arrayList

then

MyMealTypeArray.add(CBoxMealName.Text)
MyMealQtyArray.add(cint(txtMealQty.Text))

good luck
"Bhavna" <an*******@discussions.microsoft.com> wrote in message
news:7C**********************************@microsof t.com...
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 String
Public MyMealQtyArray() As Integer
Public ArrayIndex As Integer = 0

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 = "")) Then
MyMealTypeArray(ArrayIndex) = CBoxMealName.Text
MyMealQtyArray(ArrayIndex) = txtMealQty.Text

'increment the arrayIndex
ArrayIndex = ArrayIndex + 1
Else
'else display a message to state all required field are needed
MsgBox("Please ensure all the required fields are entered correctly") End If
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 DataRow

For ArrayIndex = 0 To ArrayIndex
MealInsRow = dsFullBooking.Tables("dtMealBooking").NewRow() MealInsRow("BookingNo") = "-1"
MealInsRow("RoomID") = RoomID
MealInsRow("RoomDt") = dtpRoomDate.Text
MealInsRow("Req_Session") = CBoxSession.Text
MealInsRow("Meal_Type") = CBoxMealName.Text
MealInsRow("Meal_Qty") = txtMealQty.Text
'Add the new record to the table by calling the Add method of the DataRowCollection object. dsFullBooking.Tables("dtMealBooking").Rows.Add(Mea lInsRow)
Next ArrayIndex
This is the error that i get:
An unhandled exception of type 'System.NullReferenceException' occurred in Caravan.exe Additional information: Object reference not set to an instance of an object.
My application stops at this line:
MyMealTypeArray(ArrayIndex) = CBoxMealName.Text

Can anyone see where i am going wrong?
Any help would be great.
Thanks

Jul 21 '05 #4
Cor
Hi Bhavna,

I would give almost the same answer as Mike,

I would prefer the arraylist.

and if it was the array, not the 50 but make it in your sub and than use the
index for the length of the array.

But normaly we do not help for school project you know so I will keep this
in mind..

Cor
Jul 21 '05 #5
When you declare an array, you have to gave a size but you don't have to
initialize 50 items.

in my previous reply, the correct code to declare an arrayList is:

dim al as new arraylist()
al.add(Value)

you don't have to declare size for AL.
"Bhavna" <an*******@discussions.microsoft.com> wrote in message
news:25**********************************@microsof t.com...
Hello,

I have got it working by declaring my array to be of size 50.
Public MyMealTypeArray(50) As String
Do u always need to declare the length of the array? The problem with stating the length for me is that i do not actually know this value. It is
upto the user how many entries they make!!! Also if i declare the array of length 50, do i need to enter 50 items into my array or does this simply mean anything upto 50? I tried the arraylist code that u provided but i got the same error message i stated in my first post.
Thank u for your help guys :o)
Cor, when u say u normally cannot help student projects, is it just for this group?? am i posting in the incorrect place? Sorry for keep bugging u guys. :o)

Jul 21 '05 #6
Cor
> Cor, when u say u normally cannot help student projects, is it just for
this group?? am i posting in the incorrect place?

No that is in most newsgroup.
Making homework is not good for the student, although helping is another
situation.

The difference is that I now watch to give samples.

But Mike gives the same advices as I would give in this case,

(Although I would go to look what the reject changes could do for me).

That undos all changes you have made to the dataset after the last let say
"update or fill".

Cor
Jul 21 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

19
by: Canonical Latin | last post by:
"Leor Zolman" <leor@bdsoft.com> wrote > "Canonical Latin" <javaplus@hotmail.com> wrote: > > > ... > >But I'm still curious as to the rational of having type >...
21
by: Matteo Settenvini | last post by:
Ok, I'm quite a newbie, so this question may appear silly. I'm using g++ 3.3.x. I had been taught that an array isn't a lot different from a pointer (in fact you can use the pointer arithmetics to...
5
by: JezB | last post by:
What's the easiest way to concatenate arrays ? For example, I want a list of files that match one of 3 search patterns, so I need something like DirectoryInfo ld = new DirectoryInfo(searchDir);...
3
by: Michel Rouzic | last post by:
It's the first time I try using structs, and I'm getting confused with it and can't make it work properly I firstly define the structure by this : typedef struct { char *l1; int *l2; int Nval; }...
1
by: Rob Griffiths | last post by:
Can anyone explain to me the difference between an element type and a component type? In the java literature, arrays are said to have component types, whereas collections from the Collections...
41
by: Rene Nyffenegger | last post by:
Hello everyone. I am not fluent in JavaScript, so I might overlook the obvious. But in all other programming languages that I know and that have associative arrays, or hashes, the elements in...
6
by: Robert Bravery | last post by:
Hi all, Can some one show me how to achieve a cross product of arrays. So that if I had two arrays (could be any number) with three elements in each (once again could be any number) I would get:...
1
by: Doug_J_W | last post by:
I have a Visual Basic (2005) project that contains around twenty embedded text files as resources. The text files contain two columns of real numbers that are separated by tab deliminator, and are...
16
by: mike3 | last post by:
(I'm xposting this to both comp.lang.c++ and comp.os.ms- windows.programmer.win32 since there's Windows material in here as well as questions related to standard C++. Not sure how that'd go over...
29
weaknessforcats
by: weaknessforcats | last post by:
Arrays Revealed Introduction Arrays are the built-in containers of C and C++. This article assumes the reader has some experiece with arrays and array syntax but is not clear on a )exactly how...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.