Public Conn As New ADODB.Connection
Public StrSQL As String
Private Sub Command1_Click()
Dim mRst As New ADODB.Recordset
Dim I As Integer
Dim X As Double
Dim Y As Double
X = TextBox1.Text
Y = TextBox2.Text
mRst.CursorLocation = adUseClient
StrSQL = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\db1.mdb" & ";Persist Security Info=False"
Conn.Open StrSQL
mRst.Open "Select intr From 矩阵内容表 Where N11 <= " & CStr(X) & " And N21 >= " & CStr(X) & " And N12 <= " & CStr(Y) & " And N22 >= " & CStr(Y), StrSQL, adOpenKeyset, adLockOptimistic, adCmdText
For I = 1 To mRst.RecordCount
Debug.Print mRst("intr")
mRst.MoveNext
Next
End Sub
先转换成标准一些的矩形
min(n11,n21),min(n12,n22)
max(n11,n21),max(n12,n22)
然后判断点的位置
min(n11,n21) < x < max(n11,n21) and min(n12,n22) < y < max(n12,n22)
sql语句如下:
select * from yourtable where iif(n11>n21, n21,n11) < " & x & " and iif(n11<n21, n21,n11) > " & x & " and iif(n12>n22, n22,n12) < " & y & " and iif(n12<n22, n22,n12) > " & y