求大神拯救。VB读取txt文本。关键是G怎么两次读取数值。文本如下
本帖最后由 bcrun 于 2013-04-22 15:53:02 编辑 G90 G01 X 0 Y 0
G91 G02 X40 Y20
G91 G01 Y20 Y 20
关键是 G怎么两次读取后面的数值 还有XY 的数值
下面是我做的一些程序
For i = 0 To UBound(S)
j = InStr(S(i), "X")
X(i) = Val(Mid(S(i), j + 1))
j = InStr(S(i), "Y")
Y(i) = Val(Mid(S(i), j + 1))
j = InStr(S(i), "G")
G(i) = Val(Mid(S(i), j + 1))
j = InStr(s(i), "X")
x(i) = Val(Mid(s(i), j + 1))
j = InStr(s(i), "Y")
y(i) = Val(Mid(s(i), j + 1))
j = InStr(s(i), "G")
g1(i) = Val(Mid(s(i), j + 1))
strG = Mid(s(i), j + 1)
j = InStr(strG, "G")
g2(i) = Val(Mid(strG, j + 1))
For i = 0 To UBound(S)
j = InStr(S(i), "X")
X(i) = Val(Mid(S(i), j + 1))
j = InStr(S(i), "Y")
Y(i) = Val(Mid(S(i), j + 1))
j = InStr(S(i), "G")
G(i) = Val(Mid(S(i), j + 1))
j = InStr(j + 1, S(i), "G")
G(i) = Val(Mid(S(i), j + 1))
Private Sub Form_Load()
Dim Str() As String
Dim i As Integer
Dim j As Integer
Dim S(2) As String '这里的2是我加的,不知道你的文本是几行,如果还不知道就要用REDIM
S(0) = "G90 G01 X0 Y0"
S(1) = "G91 G02 X40 Y20"
S(2) = "G91 G01 Y20 Y20"
For i = 0 To UBound(S)
Str = Split(S(i), " ", -1)
For j = 0 To UBound(Str)
MsgBox Str(j)
Next
Next
End Sub
然后你再将Str(j)分开就是了