以文本方式查看主题

-  Foxtable(狐表)  (http://www.foxtable.com/bbs/index.asp)
--  专家坐堂  (http://www.foxtable.com/bbs/list.asp?boardid=2)
----  [求助]循环计算  (http://www.foxtable.com/bbs/dispbbs.asp?boardid=2&id=52480)

--  作者:gaixuebo
--  发布时间:2014/6/16 22:39:00
--  [求助]循环计算
针对表C中每一行的第五列和第六列都进行距离运算:


Dim x1 As Double = 1
Dim y1 As Double = 1
Dim x2 As Double = 2
Dim y2 As Double = 2

Dim rad As Double = 6371
Dim p1X As Double = X1 / 180 * Math.PI
Dim p1Y As Double = Y2 / 180 * Math.PI
Dim p2X As Double = X2 / 180 * Math.PI
Dim p2Y As Double = Y2 / 180 * Math.PI
Dim result As Double = Math.Acos(Math.Sin(p1Y) * Math.Sin(p2Y) + Math.Cos(p1Y) * Math.Cos(p2Y) * Math.Cos(p2X - p1X)) * rad
msgbox(result)

最后得出的数值赋值到表C的每一行第七列 怎么计算呢


--  作者:有点甜
--  发布时间:2014/6/16 22:41:00
--  

 第五列是一个坐标,第六列是一个坐标?

 

 坐标是什么样的?(123.33,222.222)?


--  作者:gaixuebo
--  发布时间:2014/6/16 22:42:00
--  
对,已经换算成小数点形式了
--  作者:有点甜
--  发布时间:2014/6/16 22:43:00
--  
第五列的数据是怎样的?不是一行要有两个坐标,四个值么?
--  作者:gaixuebo
--  发布时间:2014/6/16 22:51:00
--  
哦,对,
For Each n As String In DataTables("表A").GetValues("第一列", "第一列 is not null")
    Dim dr1 As DataRow = DataTables("表A").Find("第一列 = \'" & n & "\'", "第二列")
    Dim dr2 As DataRow = DataTables("表A").Find("第一列 = \'" & n & "\'", "第二列 desc")
    Dim fdr As DataRow = DataTables("表D").Find("第一列 = \'" & n & "\'")
    If fdr Is Nothing Then
        fdr = DataTables("表D").AddNew
        fdr("第一列") = n
    End If
    fdr("第二列“) = math.Abs(dr2("第五列") - dr1("第五列"))
    fdr("第三列") = math.Abs(dr2("第六列") - dr1("第六列"))
Next
就比如这个函数,假设筛选出来的一对数值不再做减法运算,而筛选出是他们的经纬度,从而计算出最早与最晚的距离。然后赋值到表D中


--  作者:有点甜
--  发布时间:2014/6/16 23:28:00
--  

 如下

 

For Each n As String In DataTables("表A").GetValues("第一列", "第一列 is not null")
    Dim dr1 As DataRow = DataTables("表A").Find("第一列 = \'" & n & "\'", "第二列")
    Dim dr2 As DataRow = DataTables("表A").Find("第一列 = \'" & n & "\'", "第二列 desc")
    Dim fdr As DataRow = DataTables("表D").Find("第一列 = \'" & n & "\'")
    If fdr Is Nothing Then
        fdr = DataTables("表D").AddNew
        fdr("第一列") = n
    End If
    Dim x1 As Double = dr1("第五列")
    Dim y1 As Double = dr1("第六列")
    Dim x2 As Double = dr2("第五列")
    Dim y2 As Double = dr2("第六列")
   
    Dim rad As Double = 6371
    Dim p1X As Double = X1 / 180 * Math.PI
    Dim p1Y As Double = Y2 / 180 * Math.PI
    Dim p2X As Double = X2 / 180 * Math.PI
    Dim p2Y As Double = Y2 / 180 * Math.PI
    Dim result As Double = Math.Acos(Math.Sin(p1Y) * Math.Sin(p2Y) + Math.Cos(p1Y) * Math.Cos(p2Y) * Math.Cos(p2X - p1X)) * rad
    fdr("第二列") = result
Next


--  作者:gaixuebo
--  发布时间:2014/6/17 9:48:00
--  

Cannot set column \'第一列\'. The value violates the MaxLength limit of this column.

这个是什么问题呢?


--  作者:有点甜
--  发布时间:2014/6/17 9:51:00
--  
以下是引用gaixuebo在2014-6-17 9:48:00的发言:

Cannot set column \'第一列\'. The value violates the MaxLength limit of this column.

这个是什么问题呢?

 

第一列的字符太多,装不下。

 

你去设置一下第一列的字符长度。


--  作者:gaixuebo
--  发布时间:2014/6/17 9:58:00
--  
255还不够吗?设置成多少
--  作者:有点甜
--  发布时间:2014/6/17 9:59:00
--  
以下是引用gaixuebo在2014-6-17 9:58:00的发言:
255还不够吗?设置成多少

 

取决于你字符的长度。你的是外部数据表吗?是不是设置了约束?