473,395 Members | 1,521 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.

Using Objects as Arrays

I have 3 records in a text file called cvsAcctInfo.txt. I would like to read
these three lines and put them into an array which happens to be a defined
object. When I do this, it creates an array of 3 records; however, all three
arrays have the same information for the LAST account (3rd line in text
file).

Dim accounts(50) As Account 'bankAcct is an object of class Account
Dim count As Integer 'keeps track of the array index

'used to parse out the data in cvsAcctInfo.txt
Dim recordLine As String
Dim acctRecord()
Dim field0, field1, field2, field3, field4 As String

Dim bankAcct As New Account 'create an instance of Account

Do While (sr.Peek <> -1)

recordLine = sr.ReadLine
acctRecord = recordLine.Split(";")
field0 = acctRecord(0) : field1 = acctRecord(1) : field2 = acctRecord(2)
field3 = acctRecord(3) : field4 = CDbl(acctRecord(4))

'reads account Name
bankAcct.name = field0
cboSelectAcct.Items.Add(bankAcct.name) <--- this works!
'reads account type
bankAcct.type = field1
'reads bank name
bankAcct.bankName = field2
'reads account number
bankAcct.number = field3
'reads account balance
bankAcct.balance = field4
*** note, if I list out each record here into a listBox, they list out
correctly ****
accounts(count) = bankAcct <-- somthing is going wrong here
count += 1
Loop

Now that I have the array, I want to get the balance based on what was
selected in a combo box... so I would do something like
txtBalance.text = accounts(cboSelectAcct.SelectedIndex).balance
but of course it doesn't work because all balances are the same for each
record in my array. If anyone can help, it will be appreciated!

--
Using Objects as HoldDownTheShiftKey - forum member
http://www.visual-basic-data-mining.net/forum
Nov 21 '05 #1
2 1196
You are working with a single Account object inside the loop.

Dim bankAcct As Account
Do While (sr.Peek <> -1)
bankAcct = new Account

instead of

Dim bankAcct As New Account 'create an instance of Account
Do While (sr.Peek <> -1)

should do the trick.
Nov 21 '05 #2
You are working with a single Account object inside the loop.

Dim bankAcct As Account
Do While (sr.Peek <> -1)
bankAcct = new Account

instead of

Dim bankAcct As New Account 'create an instance of Account
Do While (sr.Peek <> -1)

should do the trick.
Nov 21 '05 #3

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

Similar topics

4
by: Christian Hackl | last post by:
I honestly wasn't able to find an answer for this design question using Google and Google Groups, so I apologize if it is asked too frequently :) Anyway: Let's say I have a multidimensional array...
5
by: John Smith | last post by:
Can someone point me to an example of how to implement and access the kind of object shown below? Most of the examples if found are an object that contains one other object. I need to create an...
9
by: Randell D. | last post by:
Folks, I can program fairly comfortably in PHP and can, for the most part using these skills and others that I've picked up over the years manage to read/understand most code in Javascript... so...
2
by: don | last post by:
My question is, do C++ array of objects hold the objects or just the pointers to the objects..... I know Java arrays only hold pointers to objects, but I seem to remember that C++ arrays hold the...
5
by: Gent | last post by:
I have two questions which are very similar: Is it possible to return an object in C++. Below is part of my code for reference however I am more concerned about the concept. It seems like the...
5
by: Gomaw Beoyr | last post by:
Hello Is there any explanation why Microsoft chose to implement arrays as objects allocated on the heap instead of structs allocated on the stack? For "mathematical stuff", one normally...
25
by: Jack | last post by:
Hi, Is there a general solution for the following problem: I have an array of instances of class B. Class B is publicly derived from class A. Then I have a class named Buffer that generally...
39
by: Mark Odell | last post by:
I've always declared variables used as indexes into arrays to be of type 'size_t'. I have had it brought to my attention, recently, that size_t is used to indicate "a count of bytes" and that using...
16
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...
1
by: bizt | last post by:
Hi, Im currently looking to move into using JSON for AJAX instead of returning from the server a string like the following: 12345{This is a text string{true I prefer objects because I dont...
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:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
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
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
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
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...

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.