Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.
If Abs(xi - x1) < Abs(0.00001 * xi) And Abs(yi - y1) < Abs(0.00001 * yi) Then F=1:GoTo 10
If Abs(xi - x2) < Abs(0.00001 * xi) And Abs(yi - y2) < Abs(0.00001 * yi) Then F=1:GoTo 10
If Abs(x1 - x2) < (0.0000001 * x1) Then If (yi - y1) * (yi - y2) < 0 Then F=2:GoTo 10 Else GoTo 20
If (xi - x1) * (xi - x2) < 0 Then F=2:GoTo 10
GoTo 20
10
If Abs(xi - x3) < Abs(0.00001 * xi) And Abs(yi - y3) < Abs(0.00001 * yi) Then F=F or 4:GoTo 30
If Abs(xi - x4) < Abs(0.00001 * xi) And Abs(yi - y4) < Abs(0.00001 * yi) Then F=F or 4:GoTo 30
If Abs(x3 - x4) < Abs(0.000001 * yi) Then If (yi - y3) * (yi - y4) < 0 Then F=F or 8:GoTo 30 Else GoTo 20
If (xi - x3) * (xi - x4) < 0 Then F=F or 8:GoTo 30
GoTo 20
30 F = 1
20
Function F(xi As Double, x1 As Double, x2 As Double, x3 As Double, x4 As Double, _
yi As Double, y1 As Double, y2 As Double, y3 As Double, y4 As Double) As Long
If (Abs(xi - x1) < Abs(0.00001 * xi) And Abs(yi - y1) < Abs(0.00001 * yi)) Or _
(Abs(xi - x2) < Abs(0.00001 * xi) And Abs(yi - y2) < Abs(0.00001 * yi)) Then
F = 1
ElseIf (Abs(x1 - x2) < (0.0000001 * x1) And (yi - y1) * (yi - y2) < 0) Or _
((xi - x1) * (xi - x2) < 0) Then
F = 2
Else
Exit Function
End If
If Not (Abs(xi - x3) < Abs(0.00001 * xi) And Abs(yi - y3) < Abs(0.00001 * yi)) And _
Not (Abs(xi - x4) < Abs(0.00001 * xi) And Abs(yi - y4) < Abs(0.00001 * yi)) Then
If Abs(x3 - x4) < Abs(0.000001 * yi) And Not ((yi - y3) * (yi - y4) < 0) Then Exit Function
If Not (Abs(x3 - x4) < Abs(0.000001 * yi)) And Not ((xi - x3) * (xi - x4) < 0) Then Exit Function
End If
F = 1
End Function
Matt
Sub Restructured()
Dim xi As Double, x1 As Double, x2 As Double, x3 As Double, x4 As Double
Dim yi As Double, y1 As Double, y2 As Double, y3 As Double, y4 As Double
Dim F As Integer
F = Abs((Abs(xi - x1) < Abs(0.00001 * xi) And Abs(yi - y1) < Abs(0.00001 * yi)) Or _
(Abs(xi - x2) < Abs(0.00001 * xi) And Abs(yi - y2) < Abs(0.00001 * yi)))
If F = 0 Then
If ((Abs(x1 - x2) < (0.0000001 * x1)) And _
((yi - y1) * (yi - y2) < 0)) Or _
((xi - x1) * (xi - x2) < 0) Then F = 2
End If
If F Then
If (Abs(xi - x3) < Abs(0.00001 * xi) And Abs(yi - y3) < Abs(0.00001 * yi)) Or _
(Abs(xi - x4) < Abs(0.00001 * xi) And Abs(yi - y4) < Abs(0.00001 * yi)) Then
F = 1
End If
If F = 2 Then
If ((Abs(x3 - x4) < Abs(0.000001 * yi)) And _
((yi - y3) * (yi - y4) < 0)) Or _
((xi - x3) * (xi - x4) < 0) Then F = 1
End If
End If
End Sub
I point out that the original code goes to some length to assign various values to F in its lower portion all of which are converted to =1 at line 30. This renders the jump to 30 unnecessary because the value =1 can be assigned immediately.
If you are experiencing a similar issue, please ask a related question
Title | # Comments | Views | Activity |
---|---|---|---|
Finding a closest match in Excel | 7 | 42 | |
Math Equation | 23 | 83 | |
Count Unique Values in column if cell matches | 3 | 24 | |
how to transpose my example data using VBA | 9 | 33 |
Join the community of 500,000 technology professionals and ask your questions.