如    asdfsafjs其他内容dfjsdfksf GXX 需要读取内容1 ZWD 需要读取内容2 ZWD 需要读取内容3 ZWD 需要读取内容4 ZWD....需要读取内容n ZWD  fadfsa其他内容dfjsdf
需要做个函数
txtzzzn=gettxt(n)
使得 txtzzzn=需要读取内容n其中 GXX为起始标志,ZWD为分割标志

解决方案 »

  1.   


    '增加一个文本框,将下面的示例数据复制至文本框,再增加一个按扭Command1
    '示例数据:asdflksf前面随便是什么,也可能还有中文jsdjfsf ZWD 这里是需要读取的数据1 GXX ZWD 这里是需要读取的数据2 GXX ZWD 这里是需要读取的数据3 GXX ZWD 这里是需要读取的数据N GXX dfasdf后面随便什么,也有可能含有中文sdfsdfsdfsdafsdafOption ExplicitPrivate Sub Command1_Click()
       MsgBox LoadData(3)
    End SubPublic Function LoadData(ByVal Index As Long) As String
       Dim StrData() As String
       Dim StrData1() As String
       Dim StrData2() As String
       Dim Count As Long
       Dim i As Long
       StrData1 = Split(Text1.Text, "ZWD")
       If UBound(StrData1) > 0 Then
         For i = 0 To UBound(StrData1)
            StrData2 = Split(StrData1(i), "GXX")
            If UBound(StrData2) > 0 Then
               Count = Count + 1
               ReDim Preserve StrData(Count)
               StrData(Count) = StrData2(0)
            End If
         Next
       End If
       
       
       If Index > Count Then
         LoadData = "未找到数据"
       Else
         LoadData = StrData(Index)
       End If
    End Function
      

  2.   


    '晕.没有发现你问题的内[容变了,
    '增加一个文本框,将下面的示例数据复制至文本框,再增加一个按扭Command1
    '示例数据:如    asdfsafjs其他内容dfjsdfksf GXX 需要读取内容1 ZWD 需要读取内容2 ZWD 需要读取内容3 ZWD 需要读取内容4 ZWD....需要读取内容n ZWD  fadfsa其他内容dfjsdf
    Option ExplicitPrivate Sub Command1_Click()
       MsgBox LoadData(1)
       MsgBox LoadData(2)
       MsgBox LoadData(3)
       MsgBox LoadData(4)
       MsgBox LoadData(5)
    End SubPublic Function LoadData(ByVal Index As Long) As String
       Dim StrData() As String
       Dim StrData1() As String
       Dim StrData2() As String
       Dim Count As Long
       Dim i As Long
       StrData1 = Split(Text1.Text, "GXX")
       If UBound(StrData1) > 0 Then
            StrData2 = Split(StrData1(1), "ZWD")
          If UBound(StrData2) > 0 Then
             For i = 0 To UBound(StrData2)
               Count = Count + 1
               ReDim Preserve StrData(Count)
               StrData(Count) = StrData2(i)
             Next
          End If
       End If
       
       
       If Index > Count Then
         LoadData = "未找到数据"
       Else
         LoadData = StrData(Index)
       End If
    End Function