subroutine assistance

H

harry

I am trying to write a subroutine where A is the array of temperature
data


lenght is the number of temperature records to be searched


and MIN and Max to return the values


i want to rite a sub routine to returnt he largest and smallest
value
of an array of an given length


ive starting with a calling line which is


CALL BigLittle(A,Length,Max,Min)


any help would be greAT
 
H

Helmut Weber

Hi Harry,

maybe not quite what you expected,
but if it helps, its alright.

Sub Test6bc()
Dim x As Long
Dim MyArr(1 To 50) As Long
Randomize
' create an array with random values
For x = 1 To 50
MyArr(x) = Int((1000 * Rnd) + 1)
Next
MsgBox Max(MyArr, 5, 40)
MsgBox Min(MyArr, 1, 20)
End Sub

Public Function Max(tmp() As Long, y1 As Long, y2 As Long) As Long
' y1 = startindex, y2 = endindex
Dim x As Long
Max = tmp(y1) ' initialize
For x = y1 To y2
If tmp(x) > Max Then
Max = tmp(x)
End If
Next
End Function

Public Function Min(tmp() As Long, y1 As Long, y2 As Long) As Long
Dim x As Long
Min = tmp(y1) ' initialize
For x = y1 To y2
If tmp(x) < Min Then
Min = tmp(x)
End If
Next
End Function

--
Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Win XP, Office 2003
"red.sys" & Chr$(64) & "t-online.de"
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top