How to Find the Largest Value in an Array in Visual Basic

Written by william nagel
  • Share
  • Tweet
  • Share
  • Pin
  • Email
How to Find the Largest Value in an Array in Visual Basic
(BananaStock/BananaStock/Getty Images)

A Visual Basic array is a data structure that allows you to store a list of values. Arrays can store any data type in Visual Basic, from integers to strings. Visual Basic does not provide a function that will automatically find the largest value in an array, but if your array stores numerical values such as integers or floating point numbers, you can program a loop that will search through the array for the largest value and output the result.

Skill level:
Easy

Other People Are Reading

Instructions

  1. 1

    Create a variable “Max” that will store the index location of the largest value in the array and initialise it to “0.” Create a variable “i” that will store the current index position in the array.

  2. 2

    Create a “For” loop. Have the loop iterate from “i=1” until it reaches the end of the array. Use the “UBound()” function on your array to return the number of items in the array; this is the number of iterations the loop will need to perform.

  3. 3

    Compare the value of the array at “Max” to the value of the array at “i.” If the value stored in “Max” is larger, continue with the loop. If the value at “i” is larger, then set “Max” equal to “i” and continue with the loop.

  4. 4

    Close the loop.

  5. 5

    Create a variable “MaxValue” that will store the highest value in the array. Set “MaxValue” equal to the value stored at “Max” in the array.

  6. 6

    Output the value of “MaxValue.”

Tips and warnings

  • Program the loop as its own function so you can reference it multiple times in your program without having to reprogram the entire loop again.

Don't Miss

Filter:
  • All types
  • Articles
  • Slideshows
  • Videos
Sort:
  • Most relevant
  • Most popular
  • Most recent

No articles available

No slideshows available

No videos available

By using the eHow.co.uk site, you consent to the use of cookies. For more information, please see our Cookie policy.