使用VB查找最小值和最大值
我正在尝试获取数组数据的最小值和最大值。。但它似乎不起作用。有人能帮我写代码吗。。Private Sub getminval_Click()
'Get Minimum and maximum Value
Dim strFileName As String
Dim myFile As Integer
Dim strTextLine As String
Dim dblX(100000) As Variant
Dim dblY(100000) As Variant
Dim dblZ(100000) As Variant
Dim arrText As Variant
Dim strName As String
Dim dblPt(2) As Double
Dim diffZ As Double
Dim minva, maxva As Integer
Dim i As Integer
Dim min(100000), max(100000) As Integer
strFileName = mstrinpfile
myFile = FreeFile
If strFileName = "" Then
MsgBox "No Data ", vbOKOnly, "HydroLab File Error"
UserForm1.Show
End If
i = 1
min(0) = 0
max(0) = 0
Open strFileName For Input As #myFile
Do While Not EOF(myFile)
Line Input #myFile, strTextLine
arrText = Split(strTextLine, ",")
dblX(i) = arrText(0)
dblY(i) = arrText(1)
dblZ(i) = arrText(2)
min(i) = dblZ(i) - min(i - 1)
If min(i) < min(i - 1) Then
minva = dblZ(i)
minval.Text = minva
ElseIf min(i) > min(i - 1) Then
minva = dblZ(i - 1)
minval.Text = minva
End If
max(i) = dblZ(i) - max(i - 1)
If max(i) > max(i - 1) Then
maxva = dblZ(i)
maxval.Text = maxva
ElseIf max(i) < max(i - 1) Then
maxva = dblZ(i - 1)
maxval.Text = maxva
End If
i = i + 1
Loop
End Sub
谢谢
页:
[1]