hi
i found some code to help me with this
Code:
Const MOODYS_TITLE As String = "Moody's"
Const SP_TITLE As String = "S&P"
Const FITCH_TITLE As String = "Fitch"
Dim sRatingAgency As String
Dim iMidLevelPostNotched As Integer
'Rating Agency
Private Sub Form_Load()
'Call Median
'MsgBox MidLevelPostNotched(17, 0, 10)
' MsgBox MidLevelPostNotched(7, 2, 0)
'median
Call MidLevelPostNotched(16, 12, 10) '12
' MsgBox MidLevelPostNotched(16, 16, 10) ' 16
'MsgBox MidLevelPostNotched(7, 7, 6)
'MsgBox MidLevelPostNotched(10, 8, 9)
sRatingAgency = ""
iMidLevelPostNotched = 0
' Call MidLevelPostNotched(0, 0, 0)
' Call MidLevelPostNotched(10, 16, 0)
' Call MidLevelPostNotched(16, 16, 10) ' 16
' Call MidLevelPostNotched(7, 7, 6)
' Call MidLevelPostNotched(10, 8, 9)
MsgBox (CStr(iMidLevelPostNotched) + " : " + sRatingAgency)
End
End Sub
Code:
Public Sub MidLevelPostNotched(iMoodys As Integer, iSP As Integer, iFitch As Integer)
Dim iHighest As Integer
Dim iArr As Variant
If iMoodys = 0 Or iSP = 0 Or iFitch = 0 Then
'get highest value
iHighest = iMoodys
sRatingAgency = MOODYS_TITLE
If iSP > iHighest Then
iHighest = iSP
sRatingAgency = SP_TITLE
End If
If iFitch > iHighest Then
iHighest = iFitch
sRatingAgency = FITCH_TITLE
End If
iMidLevelPostNotched = iHighest
Else
'get median value - Sort the array and get the mid value
iArr = Array(0, iMoodys, iSP, iFitch)
' Sort the Array and display the values in order.
BubbleSort iArr
iMidLevelPostNotched = iArr(2)
If iMidLevelPostNotched = iMoodys Then
sRatingAgency = MOODYS_TITLE
ElseIf iMidLevelPostNotched = iSP Then
sRatingAgency = SP_TITLE
ElseIf iMidLevelPostNotched = iFitch Then
sRatingAgency = FITCH_TITLE
End If
End If
End Sub
Code:
Function BubbleSort(TempArray As Variant)
Dim Temp As Variant
Dim i As Integer
Dim NoExchanges As Integer
' Loop until no more "exchanges" are made.
Do
NoExchanges = True
' Loop through each element in the array.
For i = 1 To UBound(TempArray) - 1
' If the element is greater than the element
' following it, exchange the two elements.
If TempArray(i) > TempArray(i + 1) Then
NoExchanges = False
Temp = TempArray(i)
TempArray(i) = TempArray(i + 1)
TempArray(i + 1) = Temp
End If
Next i
Loop While Not (NoExchanges)
End Function
it works which is great.
my problem is i need to change it around a bi. instead of this line
Call MidLevelPostNotched(16, 12, 10) '12
i will be reading the number from a text file and looping through it till it finishes.
now i no i will need an arrary to do this so i can pass the numbers into the MidLevelPostNotched function. but i find it hard to figure out arrays and how do to this
any one any ideas
i no it will go something like this
Code:
Do While Not EOF(fn)
Line Input #fn, sBuffer
' Input #fn, sBuffer
Loop
i can just never get the what i need in the middle part with arrays