help with arrays

jpcorzo

Member
Joined
Mar 30, 2005
Messages
6
Programming Experience
Beginner
Hi, im trying to do a program that gets some information from a notepad file, this is a name, and 3 scores. i have 5 names with its respective scores.
what im trying to do is to place the name on a name() and the scores on the average()..i already opened the file inside the vb, but i don't know how to add the name to name() and the scores to average()..
if somebody can help me,and give me some example i'd really appreciate it.
thanks in advance
JUAN
 

TPM

Well-known member
Joined
Dec 7, 2004
Messages
623
Location
CA
Programming Experience
3-5
Ok well first off you'd probably be better using arraylist's instead of arrays, there exactly the same except you can add and remove items to an arraylist. Arrays are a set length. To access a value you'd use the items index like this name(1) where 1 is the index of your name. To add an item to an arraylist you'd do this: name.add("Bob")

Hope that helps

TPM
 

jpcorzo

Member
Joined
Mar 30, 2005
Messages
6
Programming Experience
Beginner
TPM it is not working the .add..i don't know if your giving me the code for vb6.. im using vb.net. it is the same ?
 

jpcorzo

Member
Joined
Mar 30, 2005
Messages
6
Programming Experience
Beginner
ok, i know you will help on this..
let me show u in detail what i have to do..
i have a .txt file, with 5 names, each name have 3 different scores.
i.e:
JOE
75
85
95
this is how 4 more names are set..
I already opened the file on vb.net
i have
name as string() and
average as integer()
i did the loop to get everything, but now i need to add each name on name() and get the average of the 3 scores for each name on the average().
please ill really appreciate it if you help me.
 

TPM

Well-known member
Joined
Dec 7, 2004
Messages
623
Location
CA
Programming Experience
3-5
If you 'dim name() as string' it's creating an array. Do this : Dim Names as new arraylist
Then each name you read you add it to names - names.add(name)
Do the same for the averages.
add is a .net arraylist method (not VB6)
 

TPM

Well-known member
Joined
Dec 7, 2004
Messages
623
Location
CA
Programming Experience
3-5
VB.NET:
Dim Names as new arraylist
Dim Scores as new arraylist
Names.add("joe")
scores.add(85)
 

jpcorzo

Member
Joined
Mar 30, 2005
Messages
6
Programming Experience
Beginner
i know what you mean, but the purpose of the program is to get those names and scores from another file.
the input variables for the names is called nombre.
i did it like
input(1,nombre)
and then i tried like
name.add(nombre) but it didnt work.
i hope you understand me
thanks in advance Juan
 

MiloCold

Member
Joined
Mar 17, 2005
Messages
21
Programming Experience
Beginner
Hello,

Just curious, how are you connecting to the text file, can you display more of your code?

Thx,

M. Cold
 

TPM

Well-known member
Joined
Dec 7, 2004
Messages
623
Location
CA
Programming Experience
3-5
What do you mean it didn't work? Did it throw an exeption?
If you post the code for your Sub I'll look at it for you.
 
Top Bottom