|
-
Jun 25th, 2003, 03:18 PM
#1
Thread Starter
Lively Member
2d Array Rediming, Out of Bounds?
im trying to create an address book program that stores people's names and info. i have a 2d array. but the 2nd time i redim it, i get an out of bounds error. I dont know what's wrong. Here's the code:
General/Declerations:
Code:
Dim Adrs() As String '2d array to store name and info
Dim AdrC As Integer 'stores the number of people in the array
Adds name & info array:
Code:
Private Sub Command1_Click()
ReDim Preserve Adrs(AdrC, 11)
Adrs(AdrC, 0) = AName.Text
Adrs(AdrC, 1) = Address.Text
Adrs(AdrC, 2) = City.Text
Adrs(AdrC, 3) = State.Text
Adrs(AdrC, 4) = Zip.Text
Adrs(AdrC, 5) = Country.Text
Adrs(AdrC, 6) = Phone.Text
Adrs(AdrC, 7) = Work.Text
Adrs(AdrC, 8) = Cell.Text
Adrs(AdrC, 9) = Fax.Text
Adrs(AdrC, 10) = Pager.Text
AddrList.AddItem AName.Text
AdrC = AdrC + 1
'Clears TextBoxes
AName.Text = ""
Address.Text = ""
City.Text = ""
State.Text = ""
Zip.Text = ""
Country.Text = ""
Phone.Text = ""
Work.Text = ""
Cell.Text = ""
Fax.Text = ""
Pager.Text = ""
End Sub
THANKS
-
Jun 25th, 2003, 03:27 PM
#2
PowerPoster
read the on-line help on "redim"
-
Jun 25th, 2003, 03:36 PM
#3
Hyperactive Member
you might need to use 1-11 instead of 0-10
-
Jun 25th, 2003, 04:58 PM
#4
Hyperactive Member
Try to dim the Adrs() with 0, 0 (Dim Adrs(0, 0) As String)
-
Jun 25th, 2003, 05:06 PM
#5
Thread Starter
Lively Member
i got it workin, jus reversed the dimensions:
Code:
Private Sub Command1_Click()
ReDim Preserve Adrs(11, AdrC)
Adrs(0, AdrC) = AName.Text
Adrs(1, AdrC) = Address.Text
Adrs(2, AdrC) = City.Text
Adrs(3, AdrC) = State.Text
Adrs(4, AdrC) = Zip.Text
Adrs(5, AdrC) = Country.Text
Adrs(6, AdrC) = Phone.Text
Adrs(7, AdrC) = Work.Text
Adrs(8, AdrC) = Cell.Text
Adrs(9, AdrC) = Fax.Text
Adrs(10, AdrC) = Pager.Text
AddrList.AddItem AName.Text
AdrC = AdrC + 1
'ReDim Preserve Adrs(11, AdrC)
AName.Text = ""
Address.Text = ""
City.Text = ""
State.Text = ""
Zip.Text = ""
Country.Text = ""
Phone.Text = ""
Work.Text = ""
Cell.Text = ""
Fax.Text = ""
Pager.Text = ""
End Sub
-
Jun 25th, 2003, 05:13 PM
#6
In any multi-dimensional dynamic array, you can only redim the last dimension. That's why it worked only when you reversed the arguments.
To get the effect of redimming an earlier dimension, you will need to make a temporary array, copy the data from the true array to the temporary, dim the true array to the proper size, then move the data back. Moving it back can be the interesting part, since there are different ways it can be accomplished.
It seems like there was a string several months back that had a better way of doing this, but I forget what it was.
-
Jun 30th, 2003, 10:40 AM
#7
Thread Starter
Lively Member
someone told me it would be easier to use databases, but i dont know how to do databases? do u think databases would be easier?
-
Jun 30th, 2003, 01:54 PM
#8
That's a tough question to answer simply. I assume the alternative your using for storage is text files. In my experience, text files are easy to use, and really quick. However, if this gets to any size, a database is definitly easier simply because it will be easier to manage. To use text files, you have to read the whole thing in, and any organization and optimization is up to you. WIth a database, the database engine does much of that for you, and you can write quick SQL queries to get what you want. The downside of the database is that it is much more complex. The complexity isn't overwhelming, and once you get up to speed on it, it's really pretty simple, but there is much more of a learning curve, and there are lots of different options you can play with.
-
Jun 30th, 2003, 07:46 PM
#9
Thread Starter
Lively Member
so i guess i text file is good for now until i have a need to use databases.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|