VB 里 LEN 之类的什么意思?

来源:百度知道 编辑:UC知道 时间:2024/05/24 14:03:52
我要编写一个小程序计算一些数据,数据是文本中的 一些坐标值,有 X、Y、Z、A, 要计算的数据大致如下:

X-.092
Z17.5
Z8.997
Z9.022A-3.711
Z9.062A-6.319
Z9.153A-9.746
X1.444Z9.552A-1281.504
X1.448Z9.732A-1283.789
X1.452Z9.934A-1286.058
X1.455Z10.161A-1288.309
X1.459Z10.414A-1290.541
X1.463Z10.693A-1292.751

我要完成的功能是 :Z坐标值 = Z坐标值 - Text3.text/2

其中 Text3.text 里是如:10、20、30 之类的数值,
不知道如何实现,

我编了如下的程序:

Dim temp2 As String
Open "C:\tp.txt" For Input As #1
Open Text2.Text For Output As #2
Do While Not EOF(1)
Line Input #1, temp2
Dim W As String, Z

W = temp2
Z = Split(W, "Z")
For j = 1 To UBound(Z)
If Len(A(i))> 0 Then
temp2 = Replace(temp2, Z(j), Z(j) - Text3.Text / 2)
End If
Next

Print #2, temp2
Loop
Close #1
Close #2

但是有点问题,就是

当 Z坐标这行后面没有其他坐标值得 的时候 就可以计

Private Sub Command1_Click()
Dim temp2 As String, i As Long, j As Long
Open "C:\tp.txt" For Input As #1
Open Text2.Text For Output As #2
Do While Not EOF(1)
Line Input #1, temp2
Dim W As String, Z

W = temp2
Z = Split(W, "Z")
For j = 1 To UBound(Z)
If Len(Z(j)) > 0 Then
temp2 = "Z" & Val(Z(j))
Z(j) = "Z" & Z(j)
Z(j) = Replace(Z(j), temp2, Val(Mid(temp2, 2)) - Val(Text3.Text) / 2)
End If
Next
Print #2, Join(Z, "Z")
Loop
Close #1
Close #2
End Sub

代码如下:

Private Sub Command1_Click()
Dim temp2 As String
Open "C:\tp.txt" For Input As #1
Open Text2.Text For Output As #2
Do While Not EOF(1)
Line Input #1, temp2
Dim Zp, Ap As Integer
Dim z As Double
Zp = InStr(temp2, "Z")
Ap = InStr(temp2, "A")

If Zp <> 0 Then '在有Z的情况