| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1447 人关注过本帖, 2 人收藏
标题:最大值,最小值问题,盼望解决(结贴。。)
只看楼主 加入收藏
xinshous
Rank: 1
等 级:新手上路
帖 子:18
专家分:0
注 册:2010-2-22
收藏
得分:0 
1052,0.106,-0.089,0.138
1052,3.294,0.092,3.295
1052,-0.183,0.14,0.23
1052,-0.001,-0.213,0.213
1052,-0.161,0.07,0.176
1052,1.56,0.087,1.562
1052,3.94,-0.011,3.94
1052,0.173,-0.041,0.178
1052,0.133,-0.102,0.168
1052,-7.545,-0.012,7.545
1052,-0.013,-0.081,0.082
1052,-0.01,-0.193,0.193
1052,0.118,0.157,0.196
1052,-0.03,-0.18,0.182
1052,0.15,-0.054,0.159
1052,0.095,0.105,0.142

2文件
nv01,1046,1091
nv02,1049,1094
nv03,1052,1097
nv04,1055,1100

1052,-7.545这个值应该nv01、nv02、nv03都能体现
可结果是
nv01,6.877,3.367,7.547, ,-7.546,-2.808,0.001
nv02,4.569,2.979,4.969, ,-4.969,-0.39,0.014
nv03,4.806,0.371,4.807, ,-4.765,-0.324,0.005
nv04,4.372,5.326,6.653, ,-6.652,-0.374,0.011
不知为何?
另外可否传出两种结果
一种是现在的最大最小
一种是不管正负
谁差值大取谁
如最大值-7和+6,取-7
最小值,-3和1,取1
多次打扰,内心惶恐
不便之处请见谅
传上完整附件,请查看
谢谢
My Documents.rar (72.08 KB)


2010-02-22 22:42
风吹过b
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
等 级:贵宾
威 望:364
帖 子:4947
专家分:30084
注 册:2008-10-15
收藏
得分:0 
那就再加一组结果,这组结果使用 ABS(绝对值)来比较就是了.

-----------修改部分----------

'数据定义部分,增加二组变量,用来保存数据
Private Type 数据类型
    名称 As String
    范围1 As Long
    范围2 As Long
    最大值(1 To 3) As Double
    最小值(1 To 3) As Double
    最大值2(1 To 3) As Double
    最小值2(1 To 3) As Double

End Type

................

'增加一行初始化
'初始化最大值,最小值
For i = 1 To 总数
    For o = 1 To 3
        dd(i).最大值(o) = -9999999
        dd(i).最小值(o) = 9999999
        dd(i).最小值2(o) = 9999999
    Next o
Next i
.............

                    For o = 1 To 3
                        If fj(o) > dd(i).最大值(o) Then
                            dd(i).最大值(o) = fj(o)
                        End If
                        If fj(o) < dd(i).最小值(o) Then
                            dd(i).最小值(o) = fj(o)
                        End If
                        
                        '增加一组比较
                        If Abs(fj(o)) > Abs(dd(i).最大值2(o)) Then
                            dd(i).最大值2(o) = fj(o)
                        End If
                        If Abs(fj(o)) < Abs(dd(i).最小值2(o)) Then
                            dd(i).最小值2(o) = fj(o)
                        End If
                        
                    Next o
....................

'保存结果
Open 文件3 For Output As fr
For i = 1 To 总数
    Print #fr, dd(i).名称; ","; dtos(dd(i).最大值(1)); ","; dtos(dd(i).最大值(2)); ","; dtos(dd(i).最大值(3)); ", ,";
    Print #fr, dtos(dd(i).最小值(1)); ","; dtos(dd(i).最小值(2)); ","; dtos(dd(i).最小值(3))
Next i

'增加一组保存结果
Print #fr,                  '文件里空一行
For i = 1 To 总数
    Print #fr, dd(i).名称; ","; dtos(dd(i).最大值2(1)); ","; dtos(dd(i).最大值2(2)); ","; dtos(dd(i).最大值2(3)); ", ,";
    Print #fr, dtos(dd(i).最小值2(1)); ","; dtos(dd(i).最小值2(2)); ","; dtos(dd(i).最小值2(3))
Next i

Close fr

..............
'这个函数没有考虑0.000的情况,所以要修正
Private Function dtos(cs As Double) As String       '补小数前导零
    dtos = Format(cs, "#0.0#########")
End Function
--------------其余部分不变-----------------
收到的鲜花
  • xinshous2010-02-23 10:16 送鲜花  3朵  

授人于鱼,不如授人于渔
早已停用QQ了
2010-02-23 08:48
sznt
Rank: 2
等 级:论坛游民
帖 子:161
专家分:20
注 册:2005-8-4
收藏
得分:0 
风吹过b老师真让人敬佩

[ 本帖最后由 sznt 于 2010-2-23 10:18 编辑 ]
2010-02-23 09:45
xinshous
Rank: 1
等 级:新手上路
帖 子:18
专家分:0
注 册:2010-2-22
收藏
得分:0 

风吹过b老师您好,多次打搅深感不安
nv01,1046,1091
nv02,1049,1094
nv03,1052,1097
nv04,1055,1100

nv01,nv02,nv03都包含1052
可是1052,0.133,-0.102,0.168
    1052,-7.545,-0.012,7.545
    1052,-0.013,-0.081,0.082

可是    1052,-7.545,-0.012,7.545
却未出现在结果nv02,nv03中
还请老师您再看一下


结果文件:
nv01,6.877,3.367,7.547, ,-7.546,-2.808,0.001
nv02,4.569,2.979,4.969, ,-4.969,-0.39,0.014
nv03,4.806,0.371,4.807, ,-4.765,-0.324,0.005
nv04,4.372,5.326,6.653, ,-6.652,-0.374,0.011

nv01,-7.546,3.367,7.547, ,0.0,0.0,0.001
nv02,-4.969,2.979,4.969, ,0.0,-0.001,0.014
nv03,4.806,0.371,4.807, ,-0.001,0.001,0.005
nv04,-6.652,5.326,6.653, ,0.001,0.0,0.011

[ 本帖最后由 xinshous 于 2010-2-23 10:21 编辑 ]
2010-02-23 10:17
风吹过b
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
等 级:贵宾
威 望:364
帖 子:4947
专家分:30084
注 册:2008-10-15
收藏
得分:0 
重新提供 1.txt 和 2.txt 出来.

光看结果看不名堂来.

授人于鱼,不如授人于渔
早已停用QQ了
2010-02-23 14:58
xinshous
Rank: 1
等 级:新手上路
帖 子:18
专家分:0
注 册:2010-2-22
收藏
得分:0 
回复 15楼 风吹过b
重新提供附件
My Documents.rar (72.12 KB)
2010-02-23 15:15
风吹过b
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
等 级:贵宾
威 望:364
帖 子:4947
专家分:30084
注 册:2008-10-15
收藏
得分:0 
我们来分析代码,为什么不会出现在后面的记录里.

这是搜索最大值,最小值的代码段,我详细注释一下

        If bz Then              '只有全部是数字时,才去判断及求最大值\最小值
            For i = 1 To 总数        '扫描整个范围
                If fj(0) >= dd(i).范围1 And fj(0) <= dd(i).范围2 Then        '是否属于这个范围
                    For o = 1 To 3                                '对别对1 - 3 个元素的值进行处理
                        If fj(o) > dd(i).最大值(o) Then
                            dd(i).最大值(o) = fj(o)
                        End If
                        If fj(o) < dd(i).最小值(o) Then
                            dd(i).最小值(o) = fj(o)
                        End If
                        
                        If Abs(fj(o)) > Abs(dd(i).最大值2(o)) Then
                            dd(i).最大值2(o) = fj(o)
                        End If
                        If Abs(fj(o)) < Abs(dd(i).最小值2(o)) Then
                            dd(i).最小值2(o) = fj(o)
                        End If
                        
                    Next o
                    Exit For                    '已属于某个范围后,就不再搜索范围了,退出范围搜索的循环
                End If
            Next i
        End If

因为我程序里任何数据,只使用一次,所以,如果范围重复,那么将只在符合条件的第一个范围中进行判断最大值,最小值.
如果你需要所有的范围中都使用,那么那句退出 外循环的命令要去掉.


收到的鲜花
  • xinshous2010-02-24 09:41 送鲜花  3朵   附言:谢谢
  • xinshous2010-02-24 21:11 送鲜花  3朵  

授人于鱼,不如授人于渔
早已停用QQ了
2010-02-24 08:30
xinshous
Rank: 1
等 级:新手上路
帖 子:18
专家分:0
注 册:2010-2-22
收藏
得分:0 
真是太感谢了
多次打扰
真的很是抱歉
剩下的我想加两个文本框
取在这区间的最大值、最小值
仍是要两种结果
初学者可能会费点劲
但实在不好意思再麻烦了风吹过b老师了
如能有老师原滋原味的后续也更好
值此受益已是非浅
谢谢
2010-02-24 09:50
快速回复:最大值,最小值问题,盼望解决(结贴。。)
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.018989 second(s), 9 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved