473,748 Members | 6,034 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Declaring & Initializing Classes & ArrayLists

While writing this plea for help, I think I solved my
dilemma, but I don't know why the statement that solved
the problem is necessary. The inspiration for the
statement came from an undocumented VB example I found on
the web. I would be most appreciative if someone could
explain why this statement is necessary and what does it
do?

MyArt = New Art ' **** ??????? ****

Early in the code, MyArt and ArtList had been
declared with the following statements:

Public ArtList as New ArrayList
Public MyArt as New Art
'Art is a class that contains 6 Strings & 1 Integer

I am creating a Windows application which uses an
ArrayList to contain a small amount of data. ArtList, is
an instance of an ArrayList that will contain multiple
(up to 200) Art objects. MyArt is an instance of the Art
class. In the application I want to add, delete and
edit the individual Art objects in ArtList. I can
sucessfully edit the Art objects by transferring a
selected object from the ArtList to MyArt and then to the
application's Form with the following code.

MyArt = ArtList(Index)
MyArt2Form()

Then after changes have been made to the form, I transfer
the edited information from the Form, to MyArt and
finally back to ArtList with the following code:

Form2MyArt()
ArtList(Index) = MyArt

However, in the case where I want to add a new object to
the ArtList, why I must reinitialize MyArt with the
following statement?

MyArt = New Art '**** ??????? ****
Form2MyArt
ArtList.Add(MyA rt)

Thanks, GrandpaB

Nov 21 '05 #1
7 2368
Grandpa,

Did you see my answer in your origial thread accoording this question, you
did not reply on that.

Accoording too that you see that you can set an reference too an object
global as you did

When you do that as you did, than you tell with this
MyArt = ArtList(Index) MyArt is after this referencing to the same place on the heap as
ArtList(index) which references an item in the collection of ArtList

Form2MyArt()
ArtList(Index) = MyArt
And here you tell set ArtList(Index) to the adress of that MyArt (a little
bit useles when it is the same)
However, in the case where I want to add a new object to
the ArtList, why I must reinitialize MyArt with the
following statement?

MyArt = New Art '**** ??????? ****
Form2MyArt
ArtList.Add(MyA rt)


Here you create a new object and add the reference of that too the ArtList
item collection.

However I explained that more in dept my answer in the original thread with
your question.

I hope this helps?

Cor
Nov 21 '05 #2
GrandpaB,
MyArt = New Art ' **** ??????? ****
That statement declares a variable named MyArt of type Art, creates a new
Art object in heap memory, and assigns a reference to the new Art object to
the MyArt variable. The end result is that MyArt now refers to a new Art
object.

In the example it is used to create a new Art object that is then added to
the ArtList ArrayList.

You may find this article helpful:
http://www.devcity.net/net/article.a...=2004&m=1&d=22
--
Mike

Mike McIntyre
Visual Basic MVP
www.getdotnetcode.com
"GrandpaB" <an*******@disc ussions.microso ft.com> wrote in message
news:13******** *************** *****@phx.gbl.. . While writing this plea for help, I think I solved my
dilemma, but I don't know why the statement that solved
the problem is necessary. The inspiration for the
statement came from an undocumented VB example I found on
the web. I would be most appreciative if someone could
explain why this statement is necessary and what does it
do?

MyArt = New Art ' **** ??????? ****

Early in the code, MyArt and ArtList had been
declared with the following statements:

Public ArtList as New ArrayList
Public MyArt as New Art
'Art is a class that contains 6 Strings & 1 Integer

I am creating a Windows application which uses an
ArrayList to contain a small amount of data. ArtList, is
an instance of an ArrayList that will contain multiple
(up to 200) Art objects. MyArt is an instance of the Art
class. In the application I want to add, delete and
edit the individual Art objects in ArtList. I can
sucessfully edit the Art objects by transferring a
selected object from the ArtList to MyArt and then to the
application's Form with the following code.

MyArt = ArtList(Index)
MyArt2Form()

Then after changes have been made to the form, I transfer
the edited information from the Form, to MyArt and
finally back to ArtList with the following code:

Form2MyArt()
ArtList(Index) = MyArt

However, in the case where I want to add a new object to
the ArtList, why I must reinitialize MyArt with the
following statement?

MyArt = New Art '**** ??????? ****
Form2MyArt
ArtList.Add(MyA rt)

Thanks, GrandpaB

Nov 21 '05 #3

"GrandpaB" <an*******@disc ussions.microso ft.com> wrote
While writing this plea for help, I think I solved my
dilemma, but I don't know why the statement that solved
the problem is necessary.


This is the third identical post from you in 2 days, why the redundancy?

LFS
Nov 21 '05 #4
LFS,
Part of the reason for the multiple posts was confusion
on using the Newsgroups fourms. The top right window
lists the forum, but the bottom window could refereence a
different fourm. Then the search in the bottom window
searches the fourm to which it is associated, not the one
listed in the top window unless you carefully change the
forum on the search form. Thus my original post seemed
to disapear, and it was corrected by a second post to a
different fourm. The second fourm was unwittingly a VB
fourm not a VB.Net fourm. Then by this time I felt that
the problem was more abbout declaring and instaintating
variables and classes than about ListArrays so it was
refocused and resubmitted. Sorry for the long response
and confusion.

GrandpaB
-----Original Message-----

"GrandpaB" <an*******@disc ussions.microso ft.com> wrote
While writing this plea for help, I think I solved my
dilemma, but I don't know why the statement that solved the problem is necessary.
This is the third identical post from you in 2 days, why

the redundancy?
LFS
.

Nov 21 '05 #5
Cor,
No, I did not; I got lost using the Microsoft Newsgroup
forms as explained in my response to Larry.

I am just learning about Heaps & Stacks, so please bear
with me. The application can edit many art objects after
I delcare ArtList and MyArt as shown below without having
to reinstaintate MyArt.

Public ArtList as New ArrayList
Public MyArt as New Art
'Art is a class that contains 6 Strings & 1 Integer

As I have previously said the two statements:

MyArt = ArtList(Index)
ArtList(Index) = MyArt

allow me to move data back and forth between MyArt and
ArtList(Index), changing Index each time without having
to reinstaintate MyArt.

The two subroutines:

MyArt2Form()
Form2MyArt()

allow me to transfer databack and forth as many times as
I want between Form1 and MyArt without having to
reinstaintate MyArt.

I have used MyArt as temporary storage to to hold the
data while transferring it back and forth between Form1
and ArtList.

I guess I could attempt to eliminate MyArt and transfer
directly between Form1 and the ArtList. This is getting
off my original question, but could this work:

ArtList(Index). Title = tbTitle.Text
ArtList(Index). Description = tbDescription.T ext
etc, etc??

Back to the original question, if I want to add a Art
object to the ArtList collection I must first
reinstaintate MyArt as shown below:

MyArt = New Art '**** ??????? ****
Form2MyArt
ArtList.Add(MyA rt)

After the Art object has been added the user can again
edit as many members of ArtList without reinstaintating
MyArt. The only time MyArt needs to be reinstaintated si
before adding more Art to ArtList.

I know that this is probably taking more time than its
worth, but I appreciate the education, thanks

GrandpaB

-----Original Message-----
Grandpa,

Did you see my answer in your origial thread accoording this question, youdid not reply on that.

Accoording too that you see that you can set an reference too an objectglobal as you did

When you do that as you did, than you tell with this
MyArt = ArtList(Index)MyArt is after this referencing to the same place on the

heap asArtList(inde x) which references an item in the collection of ArtList

Form2MyArt()
ArtList(Index) = MyArt
And here you tell set ArtList(Index) to the adress of

that MyArt (a littlebit useles when it is the same)
However, in the case where I want to add a new object to the ArtList, why I must reinitialize MyArt with the
following statement?

MyArt = New Art '**** ??????? ****
Form2MyArt
ArtList.Add(MyA rt)
Here you create a new object and add the reference of

that too the ArtListitem collection.

However I explained that more in dept my answer in the original thread withyour question.

I hope this helps?

Cor
.

Nov 21 '05 #6
Mike,

Thanks for the URL, It was a great article, I am gaining
an appreciation for Stacks and Heaps. So far,I have been
unable to find Parts 2 & 3 to that article. As far as it
went, the article did not explain why I needed to
reinstantiate MyArt before I used the ArtList.Add(MyA rt)
method. MyArt can be used to transfer data to and from
ArtList many time without reinstantiating MyArt with:

ArtList(Index) = MyArt
MyArt = ArtList(Index)

Thanks again, GrandpaB
-----Original Message-----
GrandpaB,
MyArt = New Art ' **** ??????? ****
That statement declares a variable named MyArt of type

Art, creates a newArt object in heap memory, and assigns a reference to the new Art object tothe MyArt variable. The end result is that MyArt now refers to a new Artobject.

In the example it is used to create a new Art object that is then added tothe ArtList ArrayList.

You may find this article helpful:
http://www.devcity.net/net/article.aspx? cid=10&y=2004&m =1&d=22

--
Mike

Mike McIntyre
Visual Basic MVP
www.getdotnetcode.com
"GrandpaB" <an*******@disc ussions.microso ft.com> wrote in messagenews:13******* *************** ******@phx.gbl. ..
While writing this plea for help, I think I solved my
dilemma, but I don't know why the statement that solved
the problem is necessary. The inspiration for the
statement came from an undocumented VB example I found on the web. I would be most appreciative if someone could
explain why this statement is necessary and what does it do?

MyArt = New Art ' **** ??????? ****

Early in the code, MyArt and ArtList had been
declared with the following statements:

Public ArtList as New ArrayList
Public MyArt as New Art
'Art is a class that contains 6 Strings & 1 Integer

I am creating a Windows application which uses an
ArrayList to contain a small amount of data. ArtList, is an instance of an ArrayList that will contain multiple
(up to 200) Art objects. MyArt is an instance of the Art class. In the application I want to add, delete and
edit the individual Art objects in ArtList. I can
sucessfully edit the Art objects by transferring a
selected object from the ArtList to MyArt and then to the application's Form with the following code.

MyArt = ArtList(Index)
MyArt2Form()

Then after changes have been made to the form, I transfer the edited information from the Form, to MyArt and
finally back to ArtList with the following code:

Form2MyArt()
ArtList(Index) = MyArt

However, in the case where I want to add a new object to the ArtList, why I must reinitialize MyArt with the
following statement?

MyArt = New Art '**** ??????? ****
Form2MyArt
ArtList.Add(MyA rt)

Thanks, GrandpaB

.

Nov 21 '05 #7
>Did you see my answer in your origial thread accoording this question, you
did not reply on that. No, I did not; I got lost using the Microsoft Newsgroup forms


Than read first this what I wrote

http://groups-beta.google.com/group/...df1cd164b16e29

Nov 21 '05 #8

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

Similar topics

2
2599
by: Jody Burgess | last post by:
Hi; I am writing my first python program and would like to know how to change stdout to refer to my default printer or any other printer on my network. The other question is, Is there an API set of classes that allow me to interact with network devices. In other words, if I have a path and filename inside of a string variable in python, how do I send the file to the printer?? Thanks in advance
4
3740
by: Clint Hill | last post by:
I am working on a project that I would like to have some extensibility for later. So with this I am using interfaces to pass objects to derived classes. However I am running into a situation where two seperate classes won't cast each other even though they implement the same interface. The classes are identical yet won't convert. Here is (briefly) what I am talking about: public interface IReturnObject { Guid ID { get; set; } string...
7
1272
by: OpticTygre | last post by:
Alright, so I'm messing around with some code, and I brought up a good question to myself. If creating a class called "Person", and filling that class with variables, properties like: Public Class Person Private mstrName As String Private mdtBirthDate As Date
9
2873
by: Paul Nations | last post by:
I've got arraylists of simple classes bound to controls. I need to search through those arraylists to set the correct SelectedItem in the control. The code looks like: Public Class DegreeMaintenance Private arrCipCodes As New ArrayList 'populate reader with data With rdr Do While .Read arrCipCodes.Add(New CipCode(.GetString(0), .GetString(1)))
5
2393
by: drdave | last post by:
I would like to have ten arraylists created within a loop.. is there a conversion or something I can do to acheive this.. pseudo: Dim counter As Integer = 0 Dim ArrName As ArrayList '******** LOOP OVER THE VALUES ********************
3
3216
by: steve | last post by:
I need to compare the value of a field in a row on an arraylist with the value of a field on a second arraylist I have this bit of code working for arrays but cant get it working for arraylists The secone argument here (1) represents the second field in the row, with arraylists I get a message saying to many arguments. Can I do this with arraylists or do I need to copy the arraylists to arrays? Thanks For q As Integer = 0 To 9 For j...
24
1888
by: Daniel Rudy | last post by:
Hello Group, Consider the following code: /* form 1 */ int main(void) { int i; char *p;
8
7519
by: SM | last post by:
I've always wonder if there is diference when declaring and initializing a varible inside/outside a loop. What's a better practice? Declaring and initializing variables inside a loop routine, like this: for(var i=0; i<list; i++) { var name = list; }
4
1708
by: alexandis | last post by:
We have tables of logins (users), that differs much from standard microsoft structure - we don't use control question/answer, date fields, etc. But instead we have several additional fields. I expanded membership class and it works for logging in, but going further - creating user - I must make following in CreateUserWizard template: 1) create 'users' record filling standard microsoft fields and ignore those I don't use (mentioned...
0
8830
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,...
0
9541
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
6796
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 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...
0
6074
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();...
0
4602
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...
0
4874
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3312
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2782
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2215
bsmnconsultancy
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...

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.