473,395 Members | 1,742 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,395 software developers and data experts.

Class as an array

Still fairly new to vb.net and was wondering if it's possible to Dim a class
as an array.
And if so how do i store data to it. I have listed my code below.

Here's my code

Public Shared Function LookupEmployeeByLastName(ByVal EmployeeLastName As
String) As Employee()

Dim EmployeeDS As New DataSet

Dim EmpRecord() As Employee 'DIMENSION CLASS AS AN ARRAY

Dim EmployeeTable As DataTable

Const Strconn As String = "integrated security=SSPI;data
source=GLENNL;initial catalog=BSGData"

Dim Myconn As New SqlConnection(Strconn)

Dim MyAdapter As New SqlDataAdapter _

("Exec LookUpEmployeesByName @LastName", Myconn)

MyAdapter.SelectCommand.Parameters.Add( _

"@LastName", SqlDbType.VarChar).Value = EmployeeLastName

MyAdapter.Fill(EmployeeDS, "Employees")

EmployeeTable = EmployeeDS.Tables(0)

Dim anEmployee As DataRow

Dim iRow, nRow As Integer

nRow = EmployeeTable.Rows.Count

For iRow = 0 To nRow - 1

anEmployee = EmployeeTable.Rows(iRow)

EmpRecord(irow).FirstName = anEmployee.Item("FirstName") ' THIS IS WHERE I
RUN INTO PROBLEMS

Nexst

Return EmpRecord

Feb 5 '06 #1
1 1058

"Glenn Lacampuenga" <gl***@wcs.ab.ca> wrote in message
news:uP**************@tk2msftngp13.phx.gbl...
: Still fairly new to vb.net and was wondering if it's possible to Dim a
: class as an array.
: And if so how do i store data to it. I have listed my code below.
:
: Here's my code
:
: Public Shared Function LookupEmployeeByLastName(ByVal EmployeeLastName As
: String) As Employee()
:
: Dim EmployeeDS As New DataSet
:
: Dim EmpRecord() As Employee 'DIMENSION CLASS AS AN ARRAY
:
: Dim EmployeeTable As DataTable
:
: Const Strconn As String = "integrated security=SSPI;data
: source=GLENNL;initial catalog=BSGData"
:
: Dim Myconn As New SqlConnection(Strconn)
:
: Dim MyAdapter As New SqlDataAdapter _
:
: ("Exec LookUpEmployeesByName @LastName", Myconn)
:
: MyAdapter.SelectCommand.Parameters.Add( _
:
: "@LastName", SqlDbType.VarChar).Value = EmployeeLastName
:
: MyAdapter.Fill(EmployeeDS, "Employees")
:
: EmployeeTable = EmployeeDS.Tables(0)
:
: Dim anEmployee As DataRow
:
: Dim iRow, nRow As Integer
:
: nRow = EmployeeTable.Rows.Count
:
: For iRow = 0 To nRow - 1
:
: anEmployee = EmployeeTable.Rows(iRow)
:
: EmpRecord(irow).FirstName = anEmployee.Item("FirstName") ' THIS IS WHERE
: I RUN INTO PROBLEMS
:
: Nexst
:
: Return EmpRecord
You have not dimensioned your EmpRecord array. You define it here:
Dim EmpRecord() As Employee 'DIMENSION CLASS AS AN ARRAY
but you never state it's size. An array has a fixed length and you must
specify it at some point. What you need is something along these lines:
(Caution: untested)

nRow = EmployeeTable.Rows.Count

ReDim EmpRecord(nRow - 1)

For iRow = 0 To nRow - 1
Ralf
--
--
----------------------------------------------------------
* ^~^ ^~^ *
* _ {~ ~} {~ ~} _ *
* /_``>*< >*<''_\ *
* (\--_)++) (++(_--/) *
----------------------------------------------------------
There are no advanced students in Aikido - there are only
competent beginners. There are no advanced techniques -
only the correct application of basic principles.
Feb 5 '06 #2

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

Similar topics

1
by: Phil Powell | last post by:
Consider this: class ActionHandler { ...
7
by: Bob Rock | last post by:
Hello, this may seem a strange question, but is there a way of being able to call methods of a class through an array of that class when not referencing a specific object in the array. In other...
6
by: Johan Bergman | last post by:
Hi, Maybe someone can help me with this one. The following describes a somewhat simplified version of my problem, but I think it will be sufficient. I want to use class factories (virtual...
6
by: E G | last post by:
Hi! I am having problems in designing a class. First, I have a base class that allocates a 3D data set and allows some other mathematical operations with it, something like this: template...
3
by: matthurne | last post by:
I'm doing a chapter 12 exercise from Accelerated C++ ... writing a string-like class which stores its data in a low-level way. My class, called Str, uses a char array and length variable. I've...
9
by: justanotherguy63 | last post by:
Hi, I am designing an application where to preserve the hierachy and for code substitability, I need to pass an array of derived class object in place of an array of base class object. Since I...
6
by: thomasp | last post by:
For those who gave advice on the shortfalls of my first attempt at writing a vb.net class, Thank You. I hope that I was able to apply some of your advice to this larger atempt. At first I didn' t...
3
by: Hamilton Woods | last post by:
Diehards, I developed a template matrix class back around 1992 using Borland C++ 4.5 (ancestor of C++ Builder) and haven't touched it until a few days ago. I pulled it from the freezer and...
9
by: Soneji | last post by:
I've been learning C++ for about 6 weeks now, and I've been able to figure out pretty much everything I have had a problem with. This time, I'm at a loss. I'm not learning from the greatest book...
11
by: TinaJones095 | last post by:
Hello I am going to give a program that I have done, but I have to modifiy it, but I need help okay can you help ? Here the program I need help to straighten up below: the Java error is right at...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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
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
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,...

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.