这是1个VB编程高人写的!我不会,请用delphi翻译下,并解释下面VB代码的意思!感谢中!
Public Function ModeValue(ByVal Values As Variant) As Double
Dim i As Long
Dim LB As Long
Dim UB As Long
Dim mCount As Long
Dim mMaxCount As Long
Call SortValue(Values)
LB = LBound(Values)
UB = UBound(Values)
mCount = 1
mMaxCount = 0
ModeValue = Values(LB)
For i = LB To UB - 1
If Values(i) = Values(i + 1) Then
mCount = mCount + 1
Else
If mCount > mMaxCount Then
mMaxCount = mCount
ModeValue = Values(i)
End If
mCount = 1
End If
Next
If mCount > mMaxCount Then
ModeValue = Values(UB)
End If
End Function' 数组排序
Private Function SortValue(ByRef Values As Variant, Optional ByVal ForDirection As Boolean = True) As Long
Dim i As Long
Dim j As Long
Dim LB As Long
Dim UB As Long
Dim mFlag as Long
Dim mTemp As Variant LB = LBound(Values)
UB = UBound(Values)
IF UB - LB <= 1 Then
SortValue = 0
Exit Function
End IF For i = LB To UB - 1
For j = LB To LB + UB - i - 1
mFlag = 0
IF ForDirection Then
IF Values(j) > Values(j + 1) Then mFlag = 1
Else
IF Values(j + 1) > Values(j) Then mFlag = 1
End IF
IF mFlag = 1 Then
mTemp = Values(j)
Values(j) = Values(j + 1)
Values(j + 1) = mTemp
End If
Next
Next
SortValue = 1
End Function
Public Function ModeValue(ByVal Values As Variant) As Double
Dim i As Long
Dim LB As Long
Dim UB As Long
Dim mCount As Long
Dim mMaxCount As Long
Call SortValue(Values)
LB = LBound(Values)
UB = UBound(Values)
mCount = 1
mMaxCount = 0
ModeValue = Values(LB)
For i = LB To UB - 1
If Values(i) = Values(i + 1) Then
mCount = mCount + 1
Else
If mCount > mMaxCount Then
mMaxCount = mCount
ModeValue = Values(i)
End If
mCount = 1
End If
Next
If mCount > mMaxCount Then
ModeValue = Values(UB)
End If
End Function' 数组排序
Private Function SortValue(ByRef Values As Variant, Optional ByVal ForDirection As Boolean = True) As Long
Dim i As Long
Dim j As Long
Dim LB As Long
Dim UB As Long
Dim mFlag as Long
Dim mTemp As Variant LB = LBound(Values)
UB = UBound(Values)
IF UB - LB <= 1 Then
SortValue = 0
Exit Function
End IF For i = LB To UB - 1
For j = LB To LB + UB - i - 1
mFlag = 0
IF ForDirection Then
IF Values(j) > Values(j + 1) Then mFlag = 1
Else
IF Values(j + 1) > Values(j) Then mFlag = 1
End IF
IF mFlag = 1 Then
mTemp = Values(j)
Values(j) = Values(j + 1)
Values(j + 1) = mTemp
End If
Next
Next
SortValue = 1
End Function
解决方案 »
- 传奇源码服务器客户端`` 有人要吗?
- 用delphi难到就不能华几何图形吗
- 求救 Floating point division by zero 错误???
- 一个关于数据库的问题?
- 哪位仁兄可以帮我介绍一下用sql server等数据库应该如何连上delphi?
- 如何在dll中把数据集导入到clientdataset中。
- zrong(zr) TommyTong(童童) GreenWaterBlueSky(我的家在碧水蓝天) 进来看一看可以吗?
- delphi IdUdpclient 给服务器发送消息,返回的是TLclient的问题
- 如何动态加载bpl并调用其中的类函数
- BDE连接SQL的问题?
- 在win7旗舰版下安装了delphi2007lite,安装rbuilder出错
- indy 如何屏蔽超时链接的红框
Dim i As Long
变成
i:long;
Dim LB As Long
Dim UB As Long
Dim mCount As Long
Dim mMaxCount As Long
var
i,LB,UB,mcCount,mMaxCount:integer;
或
i,LB,UB,mcCount,mMaxCount:longint;
第二段程序是对数组进行【升序排序】并返回排序结果(数组,由ByRef定义传送地址)。如果给定无序数组元素小于2,则返回0,否则返回1。
比如对于一个数值序列:
4,2,8,5,3,0,1,7,9,6: 返回"4"
4,2,8,5,8,0,1,7,9,6: 返回"8"
4,2,8,9,8,0,1,7,9,6: 返回"8"
9,2,8,9,8,0,1,7,9,6: 返回"9"