d2jsp
Log InRegister
d2jsp Forums > Off-Topic > Computers & IT > Programming & Development > Visual Basic Question
Add Reply New Topic New Poll
Member
Posts: 25,184
Joined: Nov 21 2006
Gold: 3.95
Oct 22 2012 02:44pm
Hello, I'm currently taking a visual basic class and having a bit of a problem with the program I'm attempting to write for this assignment. I'm currently having troubles contacting my professor, so I figured I'd ask here:

I'm essentially being asked to create an array with three columns, which isn't really the problem. The problem is that I need the ability to add things to the array, which I can't find the ability to do anywhere. I've currently tried:

- Lists/Sorted Lists -> But they can only hold two columns
- Structures -> I'm not exactly sure how to use them, so I'm probably using them incorrectly.. But from what I can tell this also doesn't work.
- An actual array -> But I can't find any information on how to write to them, so I'm assuming it's not possible.


For more specific information...

I need to gather the following information:
Family yearly income
Family ID code
# of people in family/household

and organize it into an array to print later. Any advice/tips on what to use to do this?
Member
Posts: 3,064
Joined: Mar 30 2003
Gold: 5,095.00
Oct 22 2012 04:45pm
I'm not sure for your class... (because computer programming classes are stupid) but you'd want to create a class.. and create a list of your class... for instance...

keep in mind i don't write in visual basic... so.. this might be wrong.. but you'll get the idea..
Code
Public Class Family
private _yearlyincome as integer
Public Property YearlyIncome as Integer
get
return _yearlyincome
end get
set (byval value as integer)
_yearlyincome  = value
end set
private _familyidcode as integer
Public Property FamilyIdCode as Integer
get
return _familyidcode
end get
set (byval value as integer)
_familyidcode = value
end set
End Class


As you see there...

then you'd just create the objects.. and add them..

Code
dim familymember as Family
familymember.FamilyIdCode = 32232
familymemeber.YearlyIncome = 200000
dim listoffamily as new List(of Family)

listoffamily.add(familymember)


OR!!! you can simly do the same thing but create a list of arrays... Create an array for each family... and a list that contains every family...

The class is the coolest because you can do advanced awesome stuff with it using LINQ like (which i've NEVER done LINQ in visual basic... but it's something like this:)

Code
dim familiesthatmakemorethan100k = from p in listoffamily where p.YearlyIncome > 100000


yup... LINQ is badass.

This post was edited by squirrel on Oct 22 2012 04:46pm
Member
Posts: 32,925
Joined: Jul 23 2006
Gold: 3,804.50
Oct 22 2012 04:46pm
create a class that has three attributes, then use a List of that class.

or if you're a noob, you can just have 3 separate arrays/lists, one for each attribute.
Go Back To Programming & Development Topic List
Add Reply New Topic New Poll