ASP Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingASP Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old June 14th, 2003, 04:25 PM
ikea_the_sofa ikea_the_sofa is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jun 2003
Location: Spokane, WA, USA
Posts: 2 ikea_the_sofa User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Send a message via ICQ to ikea_the_sofa Send a message via AIM to ikea_the_sofa
Unhappy Problems Grasping function of Arrays

Hello everyone,

First of all let me thank you for reading my post and thank you in advance for any replies I may recieve.

I have been learning to program in VB now for the last few months and I have got the hang of all of it quickly except one feature of programming and programming in VB specifically.

I don't understand the use of an Array? Can anyone explain arrays to me in a straight forward manner and thier use.

Reply With Quote
  #2  
Old June 15th, 2003, 12:39 AM
digitallysmooth digitallysmooth is offline
you know how we do
Dev Articles Novice (500 - 999 posts)
 
Join Date: Jun 2002
Posts: 788 digitallysmooth User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 34 m 21 sec
Reputation Power: 7
ikea,

An array is simply a storage mechanism similar to a variable but more powerful.

In other words, you would use a variable like this:

firstname = "Wil"

What if you wanted to store your full name but in separate variables?

firstname = "Wil"
lastname = "Moore"
suffix = "III"

ok, simple right. Pretty clean isn't it?
Lets mess it up a bit.

Suppose you wanted to store the full names of three different people concurrently (all at the same time as opposed to using the variable once, then writing over it with a new name).

With variables you would do something like this:

person1_firstname = "Wil"
person1_lastname = "Moore"
person1_suffix = "III"

person2_firstname = "Ian"
person2_lastname = "Dunn"
person2_suffix = ""

Not too bad you might think right?
Well, that is wrong. Because there are not too many real applications where you would know how many people you are going to have to account for, and even more rarely will you be hard coding this anyhow.


Usually you won't know the amount of names to be entered so you have to make the application flexible. Its kind of like having an open bar. You could just go buy 5 cases of beer in hopes that you have estimated how many people will show up to the party and drink... or you could just have an open bar and make sure everyone has enough drinks regardless of how many people show up.

An array is just that. You initialize and use it as in the following:

Dim aryNames(3) As String

aryNames(0) = "Wil"
aryNames(1) = "Moore"
aryNames(2) = "III"

That is an array of the simplest form.
In order to use the values of an array you will have to call each item by its index. For example:

debug.print aryNames(0) & space(1) & aryNames(1) & space(1) & aryNames(2)

An array is indexed by number by default. The above array has these Indexes:

0, 1, 2

That is a total of three items, but notice our index numbers go only to 2. Arrays start with an index of zero, thus, the highest index (we call this the array's upper bound) is Its length minus one...

UpperBound = Length - 1
In this case the length is three, so its upper bound is:
3 - 1 = 2

An array has a lower bound of 0 by default. Some programming languages allow you to change an array's lower bound such as Visual basic.

You may be thinking this is enough to get you through all your programming tasks... maybe... but you should know that you can create multidimensional arrays as well as dynamic arrays. A dynamic array is most useful when you need to let the application figure out how many indexes you need instead of worrying about how many you might need. This way you don't create an array that has an upper bound that is way more than what you need, or one that is too small.

You wouldn't want to write an application where you anticipated the array's size may grow to 2000, but that would not happen for months of usage. Why waste all that space initially when you could dynamically allocate your space.

I won't go into multidimensional arrays or dynamic arrays here, but here is a sample of each:

Multidimensional Array:

Dim aryNames(2,3) As String

aryNames(0,0) = "Wil"
...
...
aryNames(1,0) = "Ian"
.
.
.

Dynamic Array:

Redim aryNames(0) As String


aryNames(UBound(aryNames)) = "Wil"

Redim Preserve aryNames(UBound(aryNames) + 1)
aryNames(UBound(aryNames)) = "Moore"
.
.
.


Hope this helps
__________________
__________________________________________________ _
Wil Moore III, MCP | Integrations Specialist | Senior Consultant
Are You Listed...? | DigitallySmooth Inc.

Last edited by laidbak : June 15th, 2003 at 01:25 AM.

Reply With Quote
  #3  
Old June 15th, 2003, 01:10 AM
stumpy's Avatar
stumpy stumpy is offline
May contain nuts.
Dev Articles Regular (2000 - 2499 posts)
 
Join Date: Aug 2002
Location: Sydney, AU
Posts: 2,058 stumpy User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 5 h 8 m 57 sec
Reputation Power: 9
Send a message via ICQ to stumpy Send a message via MSN to stumpy
Nicely put Wil... i didn't know where to start with that one... esp multi-dimensionals!
__________________
DevArticles Moderator
BlueSix - Web Development and Consulting

Reply With Quote
  #4  
Old June 15th, 2003, 01:25 AM
digitallysmooth digitallysmooth is offline
you know how we do
Dev Articles Novice (500 - 999 posts)
 
Join Date: Jun 2002
Posts: 788 digitallysmooth User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 34 m 21 sec
Reputation Power: 7
Thanks

Reply With Quote
  #5  
Old June 15th, 2003, 11:13 PM
ikea_the_sofa ikea_the_sofa is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jun 2003
Location: Spokane, WA, USA
Posts: 2 ikea_the_sofa User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Send a message via ICQ to ikea_the_sofa Send a message via AIM to ikea_the_sofa
Sweeeet.

Thanks a lot for you help Wil. I understand how arrays work a lot better now.


I hopped over to your website and took a look at the wedding pictures. It looked pretty straight. Congrats.


URL


Marcus

Reply With Quote
  #6  
Old June 15th, 2003, 11:19 PM
digitallysmooth digitallysmooth is offline
you know how we do
Dev Articles Novice (500 - 999 posts)
 
Join Date: Jun 2002
Posts: 788 digitallysmooth User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 34 m 21 sec
Reputation Power: 7
Marcus,

No problem on the array info... I'm glad it helped.
Thanks for checking out the wedding photos and the congrats.

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingASP Development > Problems Grasping function of Arrays


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway
Stay green...Green IT