px = 1.5: py = 3.5x1 = 1: x2 = 2
y1 = 3: y2 = 4
请问,如何写满足下列条件的表达式
px > x1 And px < x2
py > y1 And py < y2结果与目标差距不一 If px > x1 And px < x2 And py > y1 And py < y2 Then
结果与目标差距不一 If px > x1 And px < x2 OR py > y1 And py < y2 Then px = 1.5: py = 3.5
For xx = 0 To n1 - 2
x1 = 1: x2 = 2
For yy = 0 To n2 - 2
y1 = 3: y2 = 4
If px > x1 And px < x2 And py > y1 And py < y2 Then
intPoint(xx, yy) =
Exit For
End If
Next yy
Next xx
y1 = 3: y2 = 4
请问,如何写满足下列条件的表达式
px > x1 And px < x2
py > y1 And py < y2结果与目标差距不一 If px > x1 And px < x2 And py > y1 And py < y2 Then
结果与目标差距不一 If px > x1 And px < x2 OR py > y1 And py < y2 Then px = 1.5: py = 3.5
For xx = 0 To n1 - 2
x1 = 1: x2 = 2
For yy = 0 To n2 - 2
y1 = 3: y2 = 4
If px > x1 And px < x2 And py > y1 And py < y2 Then
intPoint(xx, yy) =
Exit For
End If
Next yy
Next xx
And 优先级高于 Or,就好比四则运算中乘号和加号的关系。
谢谢,这么简单的事,还试了半天,if语句没用过括号,将问题复杂化了.
再请问,用select ... end select 如何表示.
用两个循环解决
px = pText(0, kk): py = pText(1, kk): tt = pText(2, kk)
For xx = 0 To n1 - 2
x1 = xPoint(0, xx): x2 = xPoint(0, xx + 1)
If (px > x1 And px < x2) Then
Exit For
End If
Next xx
For yy = 0 To n2 - 2
y1 = yPoint(0, yy): y2 = yPoint(0, yy + 1)
If py > y1 And py < y2 Then
Exit For
End If
Next yy
intPoint(yy, xx) = tt原程序如下
Sub ls()
Dim SQL As String
Dim rstText As ADODB.Recordset
Dim rstLine As ADODB.Recordset
Dim xPoint As Variant, yPoint As Variant, pText As Variant, intPoint() As Variant
SQL = "Select Distinct lineStartPoint0 From [Line$]"
SQL = SQL & "Where Layer = '技术条件表'"
SQL = SQL & " Order by lineStartPoint0 Asc"
Set rstLine = ConnectRst(SQL)
n1 = rstLine.RecordCount
xPoint = rstLine.GetRows
''
SQL = "Select Distinct lineStartPoint1 From [Line$]"
SQL = SQL & "Where Layer = '技术条件表'"
SQL = SQL & " Order by lineStartPoint1 Asc"
Set rstLine = ConnectRst(SQL)
n2 = rstLine.RecordCount
yPoint = rstLine.GetRows
SQL = "Select Distinct lineEndPoint1 From [Line$]"
SQL = SQL & "Where Layer = '技术条件表'"
SQL = SQL & " Order by lineEndPoint1 Asc"
Set rstLine1 = ConnectRst(SQL)
nn2 = rstLine1.RecordCount
yPoint1 = rstLine1.GetRows
''''
SQL = "Select InsertPoint0,InsertPoint1,TextString From [Text$]"
SQL = SQL & "Where Layer = '技术条件表'"
SQL = SQL & "And InsertPoint1< 584 "
SQL = SQL & " Order by InsertPoint1 Desc ,InsertPoint0 Asc" Set rstText = ConnectRst(SQL)
pText = rstText.GetRows ''
n = rstText.RecordCount
ReDim intPoint(n2, n1) As Variant
For kk = 0 To n - 1
px = pText(0, kk): py = pText(1, kk): tt = pText(2, kk)
For xx = 0 To n1 - 2
x1 = xPoint(0, xx): x2 = xPoint(0, xx + 1)
If (px > x1 And px < x2) Then
Exit For
End If
Next xx
For yy = 0 To n2 - 2
y1 = yPoint(0, yy): y2 = yPoint(0, yy + 1)
If py > y1 And py < y2 Then
Exit For
End If
Next yy
intPoint(yy, xx) = tt
Next kk
Dim xlSheet As Worksheet
Set xlSheet = Sheets("Main")
''
xlSheet.Range("A:Z").Clear 'xlSheet.Range("A2").CopyFromRecordset rstText
xlSheet.Range("A2").Resize(n2, n1) = intPoint
End Sub