UpperBound and LowerBound of an Array Tutorial with vb.net

Good Morning! Sorry I missed yesterday as I overslept. It happens.

My eldest daughter who is 17 and will be 18 in February will return from incarceration at the county jail today. Her mother and I are extremely nervous. We don’t think her attitude has changed. We don’t think her conduct will change. She is still doing manipulative things, even while in jail. We do have her enrolled in a criminal thinking inpatient treatment program which will start after the holiday and then a outpatient program afterwards. I write this blog from my basement and I have a feeling I will be spending a lot of time down here until February. I hope for the best but I am prepared for the worst. It has been such a long ride with this child.

Today’s topic is the Upperbound and LowerBound of an Array and how it works. I received a question yesterday trying to understand this and some others in the past on this topic. It is quite basic but it is an important concept to learn. So make it a great day!

An easy way to think of a 2 dimensional array is "Rows" and Columns"
For example:
   sTwoDimArray(Row, Column)

So in sTwoDimArray(0, 1)
   "0" is the row
   "1" is the column

The LowerBound of an array is always 0, the UpperBound of the array is the total number of "rows".

So in this array:
   Dim sTwoDimArray(1,3) As String

There are 2 "rows":  0, 1
There are 4 "columns":  0, 1, 2, 3

To get the LowerBoundfor a dimension (which always returns 0):
    sTwoDimArray.GetLowerBound(0)     ‘Always Returns 0
    sTwoDimArray.GetLowerBound(1)     ‘Always Returns 0

To get the UpperBound a dimension:
   sTwoDimArray.GetUpperBound(0)       ‘Returns 1   (the first dimension was declared as 1)
   sTwoDimArray.GetUpperBound(1)       ‘Returns 3   (the second dimension was declared as 3)

 

About these ads
  1. Leave a comment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

%d bloggers like this: