我有一個文字檔內容:
Y 20.32 T 61.90
Y 21.82 T 62.30
Y 22.92 T 63.36
我用split分割字串後,我要做值的運算要怎麼做呢?
Ex: 21.82+22.92或22.92-20.32或者是61.90/22.92等這些計算
之前分割字串為:
Y=20.32 T=61.90
Y=21.82 T=62.30
Y=22.92 T=63.36
謝謝先進
2006-03-25 11:02:01 · 2 個解答 · 發問者 Anonymous in 電腦與網際網路 ➔ 程式設計
Private Sub Command1_Click()
Dim fileNa As String
Dim tmpSTR As String
Dim filenu As Integer
Dim Y(2) As Single
Dim T(2) As Single
Dim tp() As String
fileNa = "c:\Test.text"
filenu = FreeFile
i = 0
Open fileNa For Input As filenu
Do While Not EOF(filenu)
Line Input #filenu, tmpSTR
tp() = Split(tmpSTR, " ")
Y(i) = tp(1): T(i) = tp(3)
i = i + 1
Loop
Print "Y(1) + Y(2)=" + Str(Y(1) + Y(2))
Print "Y(2) - Y(0)=" + Str(Y(2) - Y(0))
Print "T(0) / Y(2)=" + Str(T(0) / Y(2))
Close #filenu
End Sub
2006-03-26 05:20:12 · answer #1 · answered by ? 4 · 0⤊ 0⤋
用陣列去儲存,再去做計算Y(0)=20.32 : T(0)=61.90Y(1)=21.82 : T(1)=62.30Y(2)=22.92 : T(2)=63.36EX:Y(1)+Y(2),Y(2)-Y(0),T(0)/Y(2)
2006-03-25 11:30:18 · answer #2 · answered by W.J.S. 7 · 0⤊ 0⤋