Solved

GetUpperBound and GetLowerbound

Posted on 2007-04-08
6
502 Views
Last Modified: 2008-02-01
I need help understanding  GetUpperBound Method and GetLowerbound Method. Could you provide a simple sample on both functions?
0
Comment
Question by:VBdotnet2005
  • 3
  • 3
6 Comments
 
LVL 85

Expert Comment

by:Mike Tomlinson
ID: 18874102
You pass the dimension of the array and the GetUpperBound() method returns the upper bound of that dimension.  The first dimension starts at 0 (zero).  The Array.Rank() method will tell you how many dimensions an array has.

GetLowerBound() always returns 0 (zero) assuming you have passed in a valid dimension for that array.

Here are some examples:

        Dim arr1(9) As Integer
        Debug.Print(arr1.Rank) ' 1
        Debug.Print(arr1.GetUpperBound(0)) ' 9

        Dim arr2(4, 5) As Integer
        Debug.Print(arr2.Rank) ' 2
        Debug.Print(arr2.GetUpperBound(0)) ' 4
        Debug.Print(arr2.GetUpperBound(1)) ' 5

        Dim arr3(7, 2, 6) As Integer
        Debug.Print(arr3.Rank) ' 3
        Debug.Print(arr3.GetUpperBound(0)) ' 7
        Debug.Print(arr3.GetUpperBound(1)) ' 2
        Debug.Print(arr3.GetUpperBound(2)) ' 6
0
 

Author Comment

by:VBdotnet2005
ID: 18880317
It looks like get the highest for GetUpperBound and get the lowest for GetLowerbound in array. Am I on the right track?
0
 
LVL 85

Expert Comment

by:Mike Tomlinson
ID: 18880342
Yes...where "highest" means get the greatest index number or slot number for the specified dimension.
0
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 

Author Comment

by:VBdotnet2005
ID: 18880398
Idle_Mind,

cool. I got that down. One thing I don't understand is Ok we know what the greatest index or lowerest index, knowing just what the index is how is that helping us?  Could you give me what we do exactly in the "real world"?
sample

       Dim arr1() As String = {"a", "b", "c"}
       
        For Each mystring As String In arr1

            MessageBox.Show(mystring) ' just for the hack of it


        Next

        MessageBox.Show(arr1.GetUpperBound(0)) '2  a is 0 b is 1 c is 2
0
 
LVL 85

Accepted Solution

by:
Mike Tomlinson earned 500 total points
ID: 18891956
"how is that helping us?  Could you give me what we do exactly in the "real world"?"

Lol...a common usage is to setup a For...Next loop to iterate over the elements of an array:

        Dim arr1() As String = {"a", "b", "c"}
        Debug.Print("arr1")
        For i As Integer = 0 To arr1.GetUpperBound(0)
            Debug.Print("Index " & i & " = " & arr1(i))
        Next

        Dim arr2(,) As String = {{"a", "b", "c"}, {"d", "e", "f"}, {"g", "h", "i"}, {"j", "k", "l"}}
        Debug.Print("arr2")
        For i As Integer = 0 To arr2.GetUpperBound(0)
            For j As Integer = 0 To arr2.GetUpperBound(1)
                Debug.Print("(" & i & "," & j & ") = " & arr2(i, j))
            Next
        Next
0
 

Author Comment

by:VBdotnet2005
ID: 18895606
Idle_Mind:

Thank you again & again :)

0

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Merging PDFs with VB.NET 10 31
DataGridView 2 29
visual Basic Net vs c# net 8 54
DataGridview Currency Formating? 22 38
Article by: Kraeven
Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
If you're writing a .NET application to connect to an Access .mdb database and use pre-existing queries that require parameters, you've come to the right place! Let's say the pre-existing query(qryCust) in Access takes a Date as a parameter and l…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now