Revision: 27928
Updated Code
at June 27, 2010 03:06 by makeev
Updated Code
Public Function IsMediana(M As Variant, Cand As Variant) As Integer Dim Pos As Integer, Neg As Integer Pos = 0: Neg = 0 If TypeName(M) = "Range" Then For i = 1 To M.Rows.Count For j = 1 To M.Columns.Count If M.Cells(i, j) > Cand Then Pos = Pos + 1 ElseIf M.Cells(i, j) < Cand Then Neg = Neg + 1 End If Next j Next i IsMediana = Pos - Neg ElseIf TypeName(M) = "Variant()" Then 'TypeName is "Variant()" Dim Val As Variant For Each Val In M If Val > Cand Then Pos = Pos + 1 ElseIf Val < Cand Then Neg = Neg + 1 End If Next Val IsMediana = Pos - Neg Else MsgBox ("") End If End Function
Revision: 27927
Updated Code
at June 27, 2010 02:57 by makeev
Updated Code
Public Function IsMediana(M As Variant, Cand As Variant) As Integer 'Ã�ðý üðÑ�Ñ�øò M ø �ûõüõýÑ� Cand. Ã� úðÑ�õÑ�Ñ�òõ �õ÷Ñ�ûÑ�Ñ�ðÑ�ð òþ÷òÑ�ðÑ�ðõÑ�Ñ�Ñ� '�ð÷ýþÑ�Ñ�Ñ� üõöôÑ� �øÑ�ûþü �ûõüõýÑ�þò üðÑ�Ñ�øòð M, ñþûÑ�Ñ�øÑ� ø üõýÑ�Ñ�øÑ� Cand. 'âõü �ðüÑ�ü üþöýþ þÿÑ�õôõûøÑ�Ñ� ñûø÷þÑ�Ñ�Ñ� Cand ú üõôøðýõ üðÑ�Ñ�øòð M. Dim Pos As Integer, Neg As Integer Pos = 0: Neg = 0 'Ã�ýðûø÷ �øÿð ÿðÑ�ðüõÑ�Ñ�ð M If TypeName(M) = "Range" Then For i = 1 To M.Rows.Count For j = 1 To M.Columns.Count If M.Cells(i, j) > Cand Then Pos = Pos + 1 ElseIf M.Cells(i, j) < Cand Then Neg = Neg + 1 End If Next j Next i IsMediana = Pos - Neg ElseIf TypeName(M) = "Variant()" Then 'TypeName is "Variant()" 'ÃÂ�þ üðÑ�Ñ�øò, ýþ ýõ �þòÑ�õü ýðÑ�Ñ�þÑ�Ñ�øù, ôûÑ� ýõóþ ýõ þÿÑ�õôõûõýÑ�, 'ýðÿÑ�øüõÑ�, ��ýúÑ�øø óÑ�ðýøÑ�: LBound, UBound. Dim Val As Variant For Each Val In M If Val > Cand Then Pos = Pos + 1 ElseIf Val < Cand Then Neg = Neg + 1 End If Next Val IsMediana = Pos - Neg Else MsgBox ("Ã��ø òÑ�÷þòõ ��ýúÑ�øø: IsMediana(M,Cand)" & _ vbCrLf & "M ýõ �òûÑ�õÑ�Ñ�Ñ� üðÑ�Ñ�øòþü øûø þñÑ�õúÑ�þü Range!") End If End Function
Revision: 27926
Initial Code
Initial URL
Initial Description
Initial Title
Initial Tags
Initial Language
at June 27, 2010 02:56 by makeev
Initial Code
Public Function IsMediana(M As Variant, Cand As Variant) As Integer 'Дан маÑÑив M и Ñлемент Cand. Ð’ качеÑтве результата возвращаетÑÑ 'разноÑÑ‚ÑŒ между чиÑлом Ñлементов маÑÑива M, больших и меньших Cand. 'Тем Ñамым можно определить близоÑÑ‚ÑŒ Cand к медиане маÑÑива M. Dim Pos As Integer, Neg As Integer Pos = 0: Neg = 0 'Ðнализ типа параметра M If TypeName(M) = "Range" Then For i = 1 To M.Rows.Count For j = 1 To M.Columns.Count If M.Cells(i, j) > Cand Then Pos = Pos + 1 ElseIf M.Cells(i, j) < Cand Then Neg = Neg + 1 End If Next j Next i IsMediana = Pos - Neg ElseIf TypeName(M) = "Variant()" Then 'TypeName is "Variant()" 'Ðто маÑÑив, но не ÑовÑем наÑтоÑщий, Ð´Ð»Ñ Ð½ÐµÐ³Ð¾ не определены, 'например, функции границ: LBound, UBound. Dim Val As Variant For Each Val In M If Val > Cand Then Pos = Pos + 1 ElseIf Val < Cand Then Neg = Neg + 1 End If Next Val IsMediana = Pos - Neg Else MsgBox ("При вызове функции: IsMediana(M,Cand)" & _ vbCrLf & "M не ÑвлÑетÑÑ Ð¼Ð°ÑÑивом или объектом Range!") End If End Function
Initial URL
http://www.intuit.ru/department/office/vbaexcel/2/vbaexcel_2.html
Initial Description
Создание процедуры Ñ Ð¿ÐµÑ€ÐµÐ¼ÐµÐ½Ð½Ñ‹Ð¼ чиÑлом параметров и обработка Ñтих параметров
Initial Title
Параметры в VBA
Initial Tags
array
Initial Language
Visual Basic