.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Gaurav Pal
Post New Web Links

How to make an array of class objects in Visual Basic

Posted By:      Posted Date: September 07, 2010    Points: 0   Category :ASP.Net
How can I make an array of objects in VB.net. Here is the requirement.Basically I have a class named hotel. I need to dynamically add customersto the hotel class using the Customer class. So basically if in the Hotelclass I can have an array of Customer objects that would be great. How can I do this in VB .net ? Public Class Hotel  ' I need an array of Customer objects. objCustomers End Class   Public Class Customer Private custId As Integer Private custName As String Private custAddress As String Private custCity As StringEnd Class Pseudo code:  Dim Hilton As Hotel = new Hotel()   Hilton.objCustomers(5) ' Declare an array of 5 customer objects   Hilton.objCustomers(0).CustId=1  Hilton.objCustomers(0).CustName="JoJo Smith"  Hilton.objCustomers(0).custAddress="122 Emory Lane"  Hilton.custCity="Merry More"  .  .  .  Hilton.objCustomers(4).CustId=1  Hilton.objCustomers(4).CustName="Ice Baby"  Hilton.objCustomers(4).custAddress="66 Domino Drive"  Hilton.custCity="Miami"    End While

View Complete Post

More Related Resource Links

Class which contains an array of objects of type "Class2"



1  Partial Class _Default
2  Inherits System.Web.UI.Page

3 Public Function Ohjoy(ByVal X As Integer) As Integer
4 Dim theClass As New Class1 '= New Class1()
5    theClass.ReSize(0)
6    theClass.myBaby(0).GetName(0) = "Hello" 'Property Chars is read only'
7    Return 1
8 End Function
I have a first class named "Class1". I have a second class named "Class2" Class2, is a member of class 1,
and is implemented as an array of objects of type Class 2.

If I try and call the Accessor GetName() my hard coded value "Hello" in my accessor is not returned? Only
an alpha character like "T"

Also if I try and assigne a value using the setter GetName() it does not work, and the compiler gives me
an error message "property Chars is ReadOnly? Does anyone know what is wrong in my code? Line 6 above


Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
End Sub
End Class

Public Class Class1
    Dim bs As Integer
    Public myBaby() As Class2
    Public myB As Class2
    Public Function ReSize(By

Basic Instincts: Collection and Array Initializers In Visual Basic 2010


Collection Initializers are a great addition to the language and allows concise syntax in order to initialize both framework and user defined collection types.

Spotty Bowles

MSDN Magazine October 2009

.NET Exceptions: Make the Transition from Traditional Visual Basic Error Handling to the Object-Orie


If you're used to Visual Basic 6.0 and you're making the transition to Microsoft .NET, you will find that error handling is quite different from what you've used for years. Visual Basic .NET uses a more object-oriented solution to signaling and responding to unexpected problems while your program is running. This approach, called structured exception handling, has a number of advantages over the On Error statements provided in previous versions of Visual Basic. For instance, exceptions give you lots more information about exactly what went wrong in your app. To help you take advantage of this modern error handling paradigm, this article will show you how to raise and respond to exceptions, as well as how to create your own custom exception classes.

Jesse Liberty

MSDN Magazine November 2002

How to create an array of VB.net objects from a VB .net class


I need to create an array of a class type. Populate the values in the class and then pass
the array to a subroutine. I havent figured out how to do this properly as I get a null
reference exception. Can someone show me how to create/instantiate the array of objects?
Here is a simple example with only one property named "_momentum". My actuall class has about
10 properties/variables in actuality

Public Class Torsion

 Dim _momentum As integer

 Public Property Momentum
            Return _momentum
    End Get
    Set(ByVal As Integer)
      _momentum = value
End Propterty

' Later in the code I try to create and object of the class

Dim x(0) As Torsion

How to make a chat program in visual basic 2008


Hi folks,

I am making a card game and i would like to make a host so that many clients can join to play, chat and share information together on a specific port or server (or whatever it is, I'm not too familiar with these)...

I would be grateful if you could provide me with some coding or anything else in vb.net to make such connection between host and many clients over the internet...

Thanks in advance.


How to run Office macros by using Automation from Visual Basic .NET

This step-by-step article describes how to call Office macros from a Visual Basic .NET Automation client.

You can use Microsoft Office Automation to open a document or create a new document that contains a Visual Basic for Applications (VBA) macro and execute the macro at run time.

Dynamically Create Controls in ASP.NET with Visual Basic .NET

This step-by-step article describes how to dynamically create controls for an ASPX Web page.

The sample project does the following:
It creates two TextBox controls.
It verifies that the TextBox contents (TextBox.text) and attributes are saved across posts to the server.
It describes how events that are posted by a dynamically created control are handled.

Make sure that the class defined in this code file matches the 'inherits' attribute, and that it e


Here is the page directive for the page that throws the error:

@ Page language="c#" Inherits="University.AspNet.Index" CodeFile="Index.aspx.cs" %>

The code behind file Index.aspx.cs starts like this:

using University.Framework.UI;

namespace University.AspNet

public partial class Index : University.Framework.UI.HomePage

The code behind is extending this HomePage class, which is in turn an extenstion of another class University.Framework.UI.Page, which extends the System.Web.UI.Page class.

Am I misusing the I

Basic Instincts: Multi-Targeting Visual Basic Applications in Visual Studio 2010


Visual Studio 2010 lets you create applications that target versions of the Microsoft .NET Framework from 2.0 to 4, and each step in between. We take a look at how multi-targeting works in Visual Studio today, and explain how you should approach multi-targeting in your projects.

Spotty Bowles

MSDN Magazine June 2010

Visual Basic: What's New in Visual Basic 2010


Learn about what's new in Visual Basic 10 straight from a program manager on Microsoft's Visual Basic team. Jonathan Aneja demonstrates time-saving features that help developers get more done with fewer lines of code.

Jonathan Aneja

MSDN Magazine April 2010

Basic Instincts: Generic Co- and Contravariance in Visual Basic 2010


Dig into the new co- and contravariance features coming in Visual Studio 2010. Binyam Kelile provides hands-on Visual Basic examples to explain how they provide more flexibility when working with generic interfaces and delegates.

Binyam Kelile

MSDN Magazine March 2010

Basic Instincts: Inspecting COM Objects With Reflection


Reflection is useful for debugging and logging and otherwise providing the type information you need. Here you'll see how to use reflection on COM types.

Lucian Wischik

MSDN Magazine January 2009

Basic Instincts: XML Programming in Visual Basic 9.0


With Visual Basic 9.0, working with XML gets much easier for developers. Here's a look at some of the new features, including LINQ support, XML literals, embedded expressions, XML properties, and XML Schema IntelliSense.

Jonathan Aneja

MSDN Magazine February 2008

Map LINQ: Create Dynamic Maps with Visual Basic 9.0 and WPF


Scott Wisniewski uses Windows Presentation Foundation data binding along with LINQ and new XML features in Visual Basic to build an interactive app that maps demographic data.

Scott Wisniewski

MSDN Magazine December 2007

Basic Instincts: Type inference in Visual Basic 2008


Visual Basic 2008 provides type inference to get the language ready to take advantage of LINQ and make your code more robust.

Bill Horst

MSDN Magazine October 2007

VISUAL BASIC: Unleash The Power Of Query In Visual Studio "Orcas"


LINQ, coming in the next version Visual Studio, codename "Orcas", adds type-safe data querying to .NET languages.

Ting Liang and Kit George

MSDN Magazine June 2007

Advanced Basics: Using RibbonX from Visual Basic


Ken Getz prepares Visual Basic developers to use RibbonX.

Ken Getz

MSDN Magazine June 2007

ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend