' Visual Basic 2008 9.0 .NET Examples - Sorting Arrays - Arrays : Module ExerciseSolution Sub Main() Dim count As Integer = 10 Dim currencies As String() = {"ATS", "DEM", "ESP", "FIM", "FRF", _ "IEP", "ITL", "LUF", "NLG", "PTE"} Dim conversionValues As Decimal() = {13.7603, 1.95583, 166.386, _ 5.94573, 6.55957, 0.787564, _ 1936.27, 40.3399, 2.20371, 200.482} ' Do Console.Write("Currencies : ") Dim index As Integer For index = 0 To count - 2 Console.Write(currencies(index) & " / ") Next Console.WriteLine(currencies(index)) Console.Write("Currency ? : ") Dim currency As String = Console.ReadLine() ' Dim lowerbound As Integer = 0 Dim upperbound As Integer = count - 1 Dim middle As Integer Dim found As Boolean = False Dim done As Boolean = False Do Until found OrElse done middle = (lowerbound + upperbound) \ 2 found = (currency = currencies(middle)) If Not found Then done = (upperbound - lowerbound < 1) If Not done Then If currency > currencies(middle) Then lowerbound = middle + 1 Else upperbound = middle - 1 End If End If End If Loop ' If found Then Console.Write("Amount " & currencies(middle) & " ? : ") Dim amount As Decimal = Console.ReadLine() Console.WriteLine("Conversion : " & amount & " " & _ currencies(middle) & " = " & _ amount / conversionValues(middle) & " EUR") Else Console.Write("Add Currency ( Y/N ) ? : ") Dim addCurrency As Char = Console.ReadLine() If addCurrency = "y"c OrElse addCurrency = "Y"c Then Console.Write("Conversion Value " & currency & _ " ( = 1 EUR ) ? : ") Dim conversionValue As Decimal = Console.ReadLine() ' ReDim Preserve currencies(count) ReDim Preserve conversionValues(count) count += 1 ' index = count - 1 Do While (index - 1 >= 0) AndAlso _ (currencies(index - 1) > currency) currencies(index) = currencies(index - 1) conversionValues(index) = conversionValues(index - 1) index -= 1 Loop currencies(index) = currency conversionValues(index) = conversionValue End If End If Loop End Sub End Module ' Visit www.studyvb.com for more examples. Copyright 2003-2008 De Wolf.