Click to See Complete Forum and Search --> : help with multidimensional arrays
IceBreakerG
Sep 29th, 2002, 09:00 PM
I'm starting my first program in VB .NET, and it's just a simple address book (name, phone numbers, address, email and maybe a few dates). And i'm not really sure how to use arrays. The way i'm doing it is i'm gonna use a list box i think that displays the contacts and the phone numbers, and when you click on a name you can display that information. But i need to know how to save information to an array, access it at any given point in the array, and edit or delete infromation from the array. And i really have no clue on how to go about doing this. Any help would be greatly appreciated.
Slow_Learner
Sep 29th, 2002, 10:17 PM
ms-help://MS.VSCC/MS.MSDNVS/cpref/html/frlrfSystemArrayClassTopic.htm
Lots of discussion, many examples. At this time, as far as I understand it you still can't delete information from an array. You may want to look at Collections also, which support adding and deleting items:
ms-help://MS.VSCC/MS.MSDNVS/vblr7/html/vaobjCollection.htm
IceBreakerG
Sep 29th, 2002, 10:58 PM
thanks, we never got to arrays in high school with this, and now that i'm in college i'm doing C so i'm not sure about much of vb now. But thanks for the help :D
BinaryAnge
Sep 29th, 2002, 11:11 PM
first of all, here is a multi dim array
DIM MyArray( integer, integer) as string
secondly, try using a structure, you like it for what you're doing.
At the top in the module declarations area.
private structure MyInfo
dim MyFriendsName as string
dim MyFriendsNumber as string
whatever else you want
end structure
dim X(integer) as MyInfo
then type X. and look at what you get.
thirdly, arrays. if you dont know how many you want, dont declare it with an amount, do it this way
DIM MyArray() as string
then use redim preserve.
redim preserve MyArray(integer)
it should be an integer 1 more than the what your array is declared at so to start, integer would be 1 and so on.
redim - redims it; preserve keeps whatever info was in the lesser parts of the array. example if your array is 10 big with info in all ten parts and you redim. you will lose that info. if you preserve it. it stays. if you redim preserve 1 higher, you keep all the old info, and expand your array 1 more. (if you use multi dim arrays, you can only redim the last dim.)
redim MyArray(cant change, can change)
hope this was helpful
BinaryAnge
Sep 29th, 2002, 11:15 PM
where i told you to type x.
you will need to specify which item in the array you want. type this
X( an integer ). <------ a dot after the )
IceBreakerG
Sep 30th, 2002, 09:48 AM
Yes that was very helpful, i wasn't sure if vb had structures in it or not. Unfortunately for me, structures is one of the reasons i failed my last programming class (wrong teacher for the class that didn't know how to explain the stuff very well). But then again it was in "C" too, but even though. Since i split up the first and last name, i will just concatenate them together, to make one item. I got visual studio .net for dummies, but in the vb part it didn't get into structures at all. So i'm gonna have to find some more books to help me read up on this stuff. I think the list box is gonna give me as much trouble as this, but i don't want to give up cuz i gotta learn :confused: But that was very helpful, thanks :D
vbforums.com
Copyright Internet.com Inc., All Rights Reserved.