首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > VB >

VB6 求最小值的有关问题?求高手解答

2012-09-29 
VB6 求最小值的问题?求高手解答VB code模块Sub CountMSFlexGrid(MSFlexGrid1 As MSFlexGrid, RowStart As

VB6 求最小值的问题?求高手解答

VB code
'模块Sub CountMSFlexGrid(MSFlexGrid1 As MSFlexGrid, RowStart As Long, RowTo As Long, ColStart As Long, ColTo As Long, MAX As Integer, MIN As Integer)   Dim Row As Integer, Col As Integer   For Row = RowStart To RowTo   For Col = ColStart To ColTo       MAX = IIf(MAX < Val(MSFlexGrid1.TextMatrix(Row, Col)), Val(MSFlexGrid1.TextMatrix(Row, Col)), MAX) '返回最大值       MIN = IIf(MIN < Val(MSFlexGrid1.TextMatrix(Row, Col)), MIN, Val(MSFlexGrid1.TextMatrix(Row, Col))) '返回最小值   Next   NextEnd Sub'窗体Private Sub Command3_Click()Dim MAX As Integer, MIN As IntegerCountMSFlexGrid MSFlexGrid1, 1, 20, 1, 20, MAX, MINText1.Text = MAXText2.Text = MINEnd Sub

上面是我求最大值、最小值的方法。为什么最大值可以求出,最小值却无法正确求出?
样本数据存在负数时最小值正确。
样本数据大于0时最小值始终是0(错误)
求高手解答

[解决办法]
MAX,MIN初始值有问题,若样本全小于0,则MAX=0(错误),反之,MIN=0;
解决:MAX,MIN初值皆取样本中第一个数值,
For Row = RowStart To RowTo前加上
VB code
MAX=Val(MSFlexGrid1.TextMatrix(RowStart, ColStart))MIN=MAX 

热点排行