473,385 Members | 1,192 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,385 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 1193
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...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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
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...

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.