473,513 Members | 2,563 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Array of Value/Ref type

wg
I am attempting to create an array of value types but seem to be haveing a
problem referencing it.

I have created a class
Public Class Tags
Private _Name As String
Private _Address As String

Public Sub New(ByVal Name As String, ByVal Address As String)
_Name = Name
_Address = Address
End Sub
Public Property Name() As String
Get
Return _Name
End Get
Set(ByVal Value As String)
_Name = Value
End Set
End Property
Public Property Address() As String
Get
Return _Address
End Get
Set(ByVal Value As String)
_Address = Value
End Set
End Property
End Class

The question is how do I create and initialize an array to reference these
objects. For instance I will populate the array myarray(x).Name = xxx, etc.
Then update based on user inputs later.

Thanks

wg
Nov 21 '05 #1
4 1226
"wg" <wg@hotmail.com> schrieb
I am attempting to create an array of value types but seem to be
haveing a problem referencing it.
Where are the value types in your example?
I have created a class
Public Class Tags
Private _Name As String
Private _Address As String

Public Sub New(ByVal Name As String, ByVal Address As String)
_Name = Name
_Address = Address
End Sub
Public Property Name() As String
Get
Return _Name
End Get
Set(ByVal Value As String)
_Name = Value
End Set
End Property
Public Property Address() As String
Get
Return _Address
End Get
Set(ByVal Value As String)
_Address = Value
End Set
End Property
End Class

The question is how do I create and initialize an array to reference
these objects. For instance I will populate the array
myarray(x).Name = xxx, etc. Then update based on user inputs later.


dim Tags(1) as tags

tags(0) = new tags
tags(1) = new tags

tags(0).name = "name1"
tags(1).name = "name2"

Does this help?

Armin
Nov 21 '05 #2
I am attempting to create an array of value types but seem to be haveing a
problem referencing it.
I don't see any value types used in your code.

The question is how do I create and initialize an array to reference these
objects. For instance I will populate the array myarray(x).Name = xxx, etc.


Dim myarray(5) As Tags
myarray(2) = New Tags("John", "John's Address")
myarray(2).Name = "xxx"

Mattias

--
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
Nov 21 '05 #3
"wg" <wg@hotmail.com> schrieb:
I have created a class
Public Class Tags
Private _Name As String
Private _Address As String

Public Sub New(ByVal Name As String, ByVal Address As String)
_Name = Name
_Address = Address
End Sub
Public Property Name() As String
Get
Return _Name
End Get
Set(ByVal Value As String)
_Name = Value
End Set
End Property
Public Property Address() As String
Get
Return _Address
End Get
Set(ByVal Value As String)
_Address = Value
End Set
End Property
End Class

The question is how do I create and initialize an array to reference these
objects. For instance I will populate the array myarray(x).Name = xxx,
etc. Then update based on user inputs later.


\\\
Dim a(9) As Tags
For i As Integer = 0 To a.Length - 1
a(i) = New Tags()
Next i
....
a(i).Name = "Bla"
///

Note that class types are reference types. When using a structure instead
of the value type some additional code is necessary.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Nov 21 '05 #4
wg
Guess I am not sure the difference between a value type and a reference
type. But between the three replys I was able to get it to work. Thanks for
the help.
wg
"wg" <wg@hotmail.com> wrote in message
news:Kv****************@bignews6.bellsouth.net...
I am attempting to create an array of value types but seem to be haveing a
problem referencing it.

I have created a class
Public Class Tags
Private _Name As String
Private _Address As String

Public Sub New(ByVal Name As String, ByVal Address As String)
_Name = Name
_Address = Address
End Sub
Public Property Name() As String
Get
Return _Name
End Get
Set(ByVal Value As String)
_Name = Value
End Set
End Property
Public Property Address() As String
Get
Return _Address
End Get
Set(ByVal Value As String)
_Address = Value
End Set
End Property
End Class

The question is how do I create and initialize an array to reference these
objects. For instance I will populate the array myarray(x).Name = xxx,
etc. Then update based on user inputs later.

Thanks

wg

Nov 21 '05 #5

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

Similar topics

15
5156
by: lawrence | last post by:
I wanted to test xml_parse_into_struct() so I took the example off of www.php.net and put this code up on a site: <?php $simple = <<<END <item>
58
10050
by: jr | last post by:
Sorry for this very dumb question, but I've clearly got a long way to go! Can someone please help me pass an array into a function. Here's a starting point. void TheMainFunc() { // Body of...
4
38233
by: Mark Hannon | last post by:
I am trying to initialize an array only once so it can be seen & used by any functions that need it. As I understand it, if a variable is declared by itself outside of any functions, its scope is...
6
4117
by: Herrcho | last post by:
in K&R Chapter 6.3 it mentions two methods to calculate NKEYS. and points out the first one which is to terminate the list of initializers with a null pointer, then loop along keytab until the...
204
12895
by: Alexei A. Frounze | last post by:
Hi all, I have a question regarding the gcc behavior (gcc version 3.3.4). On the following test program it emits a warning: #include <stdio.h> int aInt2 = {0,1,2,4,9,16}; int aInt3 =...
32
6471
by: Joe Rattz | last post by:
Hmmm, I wrote the following code. I want an array of bools and I want to intialize them to false. bool bits = new bool; foreach(bool bit in bits) { bit = false; } The compiler complains...
0
2449
by: Max M. Power | last post by:
I'm getting an InvalidOperationException calling Invoke with a method parameter object array that contains a two dimentional string array. More stack trace output below: // Create two...
45
4764
by: VK | last post by:
(see the post by ASM in the original thread; can be seen at <http://groups.google.com/group/comp.lang.javascript/browse_frm/thread/3716384d8bfa1b0b> as an option) As that is not in relevance to...
1
2249
by: assgar | last post by:
Hi I need help solving a porblem. I have a form that displays a checkbox, service code, description and dropdown with fees on each row. The fee_money and unit array only returns a...
37
1955
by: Richard Heathfield | last post by:
candide said: They aren't. An array is an array. An address is a pointer value. These are not the same thing. If you mean that &array and &array are the same, they aren't. They have different...
0
7259
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
7158
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...
0
7380
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
7535
jinu1996
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...
0
5683
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,...
1
5085
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...
0
3232
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...
0
3221
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
798
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.