How to Find the Largest Value in an Array in Visual Basic
- 1). Create a variable "Max" that will store the index location of the largest value in the array and initialize it to "0." Create a variable "i" that will store the current index position in the array.
- 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). 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). Close the loop.
- 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). Output the value of "MaxValue."