Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Swap min val with max in array
#2
Solved: 9 Years, 9 Months, 3 Weeks ago
Code:
sort = Array(10,5,20,35,15)

smallest = sort(0) 'Assuming
greatest = sort(0) 'Assuming

For i = 1 To UBound(sort)
    
    'Looking for smallest
    If sort(i) < smallest then
        smallest = sort(i)
        small_index = i
    End If
    'Looking for greatest
    If sort(i) > greatest then
        greatest = sort(i)    
        great_index = i
    End If
    
Next

'Swapping Values
sort(small_index) = greatest
sort(great_index) = smallest

'Just confirming
For y = o To 4
    msgbox sort(y)
Next
Reply


Messages In This Thread
Swap min val with max in array - by Azharqurahi - 07-23-2014, 01:02 PM
RE: Swap min val with max in array - by Ankur - 07-23-2014, 11:20 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  How to convert a single dimension array to two dimensional array venkatesh9032 3 5,237 02-10-2014, 03:07 PM
Last Post: pranikgarg
  Adding array to another Global array in VB Script test911 1 3,012 12-02-2012, 12:40 PM
Last Post: parminderdhiman84

Forum Jump:


Users browsing this thread: 1 Guest(s)