a82613035
|
分享:
▼
x1
|
[Basic][求助] 如何在(记事本) AAA.TXT,里座标排序 (Q4)由大排小 (Q2)由小排大(Q3)由大排小 (Q1)由小排大
X13.50Y1096.00T210 X32.50Y13.00T210 X13.50Y42.00T210 X32.50Y38.00T210 X13.50Y1056.00T210 X13.50Y13.00T210 X523.50Y1096.00T210 X521.50Y36.00T210 X33.50Y1096.00T210 X53.50Y1096.00T210 X538.50Y1081.00T210 X13.50Y1076.00T210 X538 .. 访客只能看到部份内容,免费 加入会员 或由脸书 Google 可以看到全部内容
|
|
x0
[楼 主]
From:台湾中华电信 | Posted:2010-09-25 13:33 |
|
|
ebolaman
级别: 副版主
版区: 程式设计
x38
x458
|
分享:
▲
▼
大致上了解,这是第二次修改
不过还是搞不懂到底要依照何种标准来排序
假如要修改,只要调 CmpPos 函数里的东西即可 Form1:复制程式
Option Explicit
Private Sub Command1_Click()
Dim S As String
Dim Arr() As String
Dim i As Long, k As Long, XYInd As Integer
Dim B As Boolean
Dim CmpMethod1 As Integer, CmpMethod2 As Integer
'------------ Ini. Var. ------------
CmpMethod1 = IIf(Option1(0).Value = True, 1, 0) 'Sort By Y or not
CmpMethod2 = IIf(Check1.Value = 1, 2, 1) 'Increasing or not
'--------- Put Datas Into Array -----------
S = Trim(Text1.Text)
Do While Right(S, 2) = vbNewLine
S = Left(S, Len(S) - 2)
Loop
Arr = Split(S, vbNewLine)
k = UBound(Arr)
ReDim Pos(k, 1) As Double
For i = 0 To k
Pos(i, 0) = GetUserVal(Arr(i), 0) 'X
Pos(i, 1) = GetUserVal(Arr(i), 1) 'Y
Next i
'-------- Sort ----------
'Bubble Sort
For XYInd = 0 To 1
Do
i = 0
B = False
Do
If CmpPos(Pos, i, CmpMethod1, CmpMethod2, XYInd) Then
ExcgPos Pos, i
B = True
End If
i = i + 1
Loop While i < k
Loop While B
Next XYInd
'---------- Show Result ---------
S = ""
For i = 0 To k
S = S & "(" & Pos(i, 0) & ", " & Pos(i, 1) & ")" & vbNewLine
Next i
Text2.Text = S
End Sub
Public Function GetUserVal(ByVal S As String, ByVal Typ As Byte) As Double
Dim m As Long, m2 As Long
'Kill Str T...
m = InStrRev(UCase(S), "T")
If m <> 0 Then S = Left(S, m - 1)
'''
m = InStr(1, UCase(S), "X")
m2 = InStr(m + 1, UCase(S), "Y")
GetUserVal = IIf(Typ = 0, Mid(S, m + 1, m2 - m - 1), Right(S, Len(S) - m2))
End Function
Public Sub ExcgPos(ByRef P() As Double, ByVal i As Long) 'Exchange Two Pos.
Dim tempk As Double, tempk2 As Double
tempk = P(i, 0): tempk2 = P(i, 1)
P(i, 0) = P(i + 1, 0): P(i, 1) = P(i + 1, 1)
P(i + 1, 0) = tempk: P(i + 1, 1) = tempk2
End Sub
Public Function CmpPos(ByRef P() As Double, ByVal i As Long, ByVal Mtd1 As Integer, ByVal Mtd2 As Integer, ByVal Ind As Integer) As Boolean
Dim FixedMtd As Integer
If Ind = 0 Then
If Mtd2 = 2 Then
CmpPos = (P(i, Mtd1) > P(i + 1, Mtd1))
Else
CmpPos = (P(i, Mtd1) < P(i + 1, Mtd1))
End If
Else
FixedMtd = Mtd1
Mtd1 = CByte(Not CBool(Mtd1 * 255)) / 255 'Reverse 0 & 1
If Mtd2 = 2 Then
CmpPos = (P(i, Mtd1) > P(i + 1, Mtd1)) And (P(i, FixedMtd) = P(i + 1, FixedMtd))
Else
CmpPos = (P(i, Mtd1) < P(i + 1, Mtd1)) And (P(i, FixedMtd) = P(i + 1, FixedMtd))
End If
End If
End Function
[ 此文章被ebolaman在2010-09-30 04:33重新编辑 ]
此文章被评分,最近评分记录财富:50 (by 三仙) | 理由: ^^ 因为您的参与,让程式设计更容易!! | |
|
|
|
|
ebolaman
级别: 副版主
版区: 程式设计
x38
x458
|
分享:
▲
▼
下面是引用 a82613035 于 2010-09-30 07:46 发表的 : ebolaman你好 : 我有一个 长( X )552. 宽(Y)1109. 座标分为四个角落,四个角设定为Q1,Q2,Q3,Q4 为四个角落 Q1为 (X0. Y0.) , Q2为(X552. Y0.) , Q3为(X0. Y1109.) , Q4为( X552. Y1109.) 1: 首先开启 入径C:\ XXX \AAA.TXT (记事本),把( T210 或是T313或是T235或是T304等)无排序座标重新排列座标,把四个角落Q1,Q2,Q3,Q4,由外面排到里面,例如座标分布再Q4位置座标外面排到里面,座标分布再Q2位置座标外面排到里面,座标分布再Q3位置座标外面排到里面,座标分布再Q1位置座标外面排到里面,由Q4角落排到---Q2角落排到--- Q3角落排到--- Q1角落排到 下面是座标无排序 ....... 所以我先归纳一下规则: Q1 : Y 主递增、X其次 Q2 : Y 主递增、X接着递减
Q3 : X 主递增、Y接着递减 Q4 : Y 主递减、X其次是吗? 我另做了一个图来展示以上意义: 不过有几点我搞不太清楚: 1. 真的是照以上规则吗? 不是照与某点距离? 2. 字串后面的 TXXX 是做什么的 3. 输出格式必须保持与原本相同吗? 例如: X123Y345T6784. 输入来源有 Q1, Q2... 等字样吗? 归纳出以上规则后,相信会比较好了解排序之最终目的 我已把大致上的 VB 程式码打好了,或许你先行修改看看
[ 此文章被ebolaman在2010-09-30 20:20重新编辑 ]
|
|
|