Option Compare Database
Option Explicit
Public Sub SUMMIN()
Dim rst As DAO.Recordset
Dim N As Integer 'количество пар
Dim i As Integer
Dim j As Integer
Dim m1 As Double
Dim m2 As Double
Dim Result As Double
Dim varmas
Set rst = CurrentDb.OpenRecordset("Таблица1")
With rst
N = (rst.Fields.Count - 1) / 2
ReDim varmas(N)
.MoveFirst
While Not .EOF ' на случай множества записей
For j = 1 To N
varmas(j) = rst.Fields(j) + rst.Fields(j + N)
Next
'вывод код, сумма двух минимальных
Debug.Print .Fields(0), summin2(varmas, N)
.MoveNext
Wend
End With
End Sub
Public Function summin2(mas As Variant, ubm As Integer)
Dim m1 As Double
Dim m2 As Double
Dim i As Integer
Dim NomMin1 As Integer
m1 = 99999999
m2 = 99999999
NomMin1 = 1
For i = 1 To ubm
If mas(i) < m1 Then
m1 = mas(i)
NomMin1 = i
End If
Next
For i = 1 To ubm
If i <> NomMin1 Then
If mas(i) < m2 Then
m2 = mas(i)
End If
End If
Next
summin2 = m1 + m2
End Function
|