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.Tex t = "")) The
MyMealTypeArray (ArrayIndex) = CBoxMealName.Te x
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.T ables("dtMealBo oking").NewRow(
MealInsRow("Boo kingNo") = "-1
MealInsRow("Roo mID") = RoomI
MealInsRow("Roo mDt") = dtpRoomDate.Tex
MealInsRow("Req _Session") = CBoxSession.Tex
MealInsRow("Mea l_Type") = CBoxMealName.Te x
MealInsRow("Mea l_Qty") = txtMealQty.Tex
'Add the new record to the table by calling the Add method of the DataRowCollecti on object.
dsFullBooking.T ables("dtMealBo oking").Rows.Ad d(MealInsRow
Next ArrayInde
This is the error that i get
An unhandled exception of type 'System.NullRef erenceException ' 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.Te x
Can anyone see where i am going wrong
Any help would be great
Thank 6 1574
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.rejectc hanges 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.Tex t = "")) Then MyMealTypeArray (ArrayIndex) = CBoxMealName.Te xt 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.T ables("dtMealBo oking").NewRow( ) MealInsRow("Boo kingNo") = "-1" MealInsRow("Roo mID") = RoomID MealInsRow("Roo mDt") = dtpRoomDate.Tex t MealInsRow("Req _Session") = CBoxSession.Tex t MealInsRow("Mea l_Type") = CBoxMealName.Te xt MealInsRow("Mea l_Qty") = txtMealQty.Text 'Add the new record to the table by calling the Add method of the
DataRowCollecti on object. dsFullBooking.T ables("dtMealBo oking").Rows.Ad d(MealInsRow) Next ArrayIndex
This is the error that i get: An unhandled exception of type 'System.NullRef erenceException ' 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.Te xt
Can anyone see where i am going wrong? Any help would be great. Thanks
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
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(CBoxMealNa me.Text)
MyMealQtyArray. add(cint(txtMea lQty.Text))
good luck
"Bhavna" <an*******@disc ussions.microso ft.com> wrote in message
news:7C******** *************** ***********@mic rosoft.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.Tex t = "")) Then MyMealTypeArray (ArrayIndex) = CBoxMealName.Te xt 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.T ables("dtMealBo oking").NewRow( ) MealInsRow("Boo kingNo") = "-1" MealInsRow("Roo mID") = RoomID MealInsRow("Roo mDt") = dtpRoomDate.Tex t MealInsRow("Req _Session") = CBoxSession.Tex t MealInsRow("Mea l_Type") = CBoxMealName.Te xt MealInsRow("Mea l_Qty") = txtMealQty.Text 'Add the new record to the table by calling the Add method of the
DataRowCollecti on object. dsFullBooking.T ables("dtMealBo oking").Rows.Ad d(MealInsRow) Next ArrayIndex
This is the error that i get: An unhandled exception of type 'System.NullRef erenceException ' 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.Te xt
Can anyone see where i am going wrong? Any help would be great. Thanks
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
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*******@disc ussions.microso ft.com> wrote in message
news:25******** *************** ***********@mic rosoft.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)
> 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 This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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
> >pointer-to-array-of-size-N-of-type-T (which is fine) and not having type
> >array-of-size-N-of-type-T (with some exceptions, which is curious).
> > So far
> >the consensus seems to be that while everyone is aware of this no one
knows
|
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 "browse" it). So I
expected that when I run this program, I get both c1.A and c2.A
pointing to the same address, and changing c1.A means that also c2.A
changes too.
----- BEGIN example CODE -----------
|
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);
pfiles = ld.GetFiles("*.aspx.resx|") + ld.GetFiles("*.ascx.resx") +
ld.GetFiles("*.master.resx");
but of course there is no + operation allowed on the FileInfo arrays
returned by the GetFiles method.
|
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; } *arrays;
It's supposed to be a structure containing an array of chars, an array
of ints and an int.
I declare functions like this : arrays *parseline(char *line, int N)
|
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 Framework are said to have an element
type.
http://java.sun.com/docs/books/jls/second_edition/html/arrays.doc.html
| |
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 the
hash are alphabetically sorted if the key happens to
be alpha numeric. Which I believe makes sense because
it allows for fast lookup of a key.
|
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:
the two arrays
{"one","two","three"},{"red","green","blue}
the result
one red
one green
|
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 of
different lengths (e.g. usually between 25 and 45 rows. The columns in
each file have the same length). The text files have been numbered
sequentially e.g. cb0, cb1, cb2 and so on. I would like to read the
data from each text file into...
|
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 at just comp.lang.c++. If one of
these groups is
too inappropriate, just take it off from where you send your replies.)
Hi.
|
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 multi-dimensional arrays work, b) how to call
a function with a multi-dimensional array, c) how to return a multi-dimensional array from a function,
or d) how to read and write arrays from a disc file.
Note to C++ programmers: You should be using...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
|
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |