我有一個檔案內容為
M01
A33.00C-25.25B36.20Y20.30X33.00Z10.10
A31.00C-21.25B31.20Y21.30X31.00Z11.10
排序後變成
M01
A33.00B36.20C-25.25X33.00Y20.30Z10.10
A31.00B31.20C-21.25X31.00Y21.30Z11.10
然後取值運算,例如:
A+B=33.00+36.20=69.20
A+B=31.00+31.20=62.20
請問要怎麼用排序後取值出來呢?
2006-05-14 14:01:15 · 1 個解答 · 發問者 Anonymous in 電腦與網際網路 ➔ 程式設計
請問這行的意思是什麼呢
For I = 2 To Len(S)
2006-05-15 18:00:36 · update #1
如果我要分別拿出來要怎麼做呢?
如:
A=33.00 B=36.20 C=-25.25
2006-05-16 11:18:53 · update #2
如果資料多筆的話
A33.00B36.20C-25.25X33.00Y20.30Z10.10
A31.00B31.20C-21.25X31.00Y21.30Z11.10
要怎麼做呢?
因為我做出來的會有多很多個不必要的東西
2006-05-16 20:55:28 · update #3
'我只做如何將字串拆開再排序計算的部分,其他關於讀檔的部分查一下知識+就有Private Sub Command1_Click()Dim A() As String, B As Boolean, I%, J%, T#, S$, X$S = "A33.00C-25.25B36.20Y20.30X33.00Z10.10"'令X=A~BFor I = 65 To 90 X = X & Chr(I)NextDo B = False For I = 2 To Len(S) If InStr(X, Mid$(S, I, 1)) Then '若Mid$(S, I, 1)是英文字,就將此字母之前的字串代入A(J) ReDim Preserve A(J) A(J) = Left(S, I - 1) '將此字串從S字串中移除 S = Mid$(S, I) J = J + 1 B = True '表示有找到英文字 Exit For End If NextLoop Until B = False '沒有找到英文字就離開迴圈ReDim Preserve A(J) '將S代入A(J),此時S=Z10.10A(J) = S'排序For I = 0 To UBound(A) For J = I To UBound(A) If A(I) > A(J) Then X = A(I): A(I) = A(J): A(J) = X Next '若A(I)的第1字為A或B就相加 If Left(A(I), 1) = "A" Or Left(A(I), 1) = "B" Then T = T + Val(Mid(A(I), 2))Next'輸出Print Join(A, "")Print "A + B = "; Format(T, "0.00")End Sub
2006-05-16 00:34:24 補充:
For I = 2 To Len(S)從S字串的第2個字開始讀取
2006-05-16 18:59:36 補充:
For I = 0 To UBound(A) Print Left(A(I), 1); "="; Mid(A(I), 2)Next
2006-05-15 08:10:34 · answer #1 · answered by W.J.S. 7 · 0⤊ 0⤋