如何将第一行的数据显示在一个list1列表中,然后选择相应的数据,在list2列表中显示所对应的数据,然后list2中只显示数据的第一列,当在list2中选择相应的数据时,又能在text1和text2中显示相应的第二列和第三列数据。谢谢!还有在增加第一行数据时,比如我要增加一个d,e系列的参数时,程序能自动的调入。数据格式如下:a,b,cstart_a
1,2,3
4,5,6
7,8,9
end_astart_b
10,20,30
40,50,60
70,80,90
end_bstart_c
100,200,300
400,500,600
700,800,900
end_c

解决方案 »

  1.   


    Dim arrLine1() As String
    Private Sub Command1_Click()
    Dim strTmp1 As String, tmp1 As String
    Open "c:/file1.txt" For Input As #1
    Do Until EOF(1)
        Line Input #1, tmp1
        If Len(Trim(tmp1)) <> 0 Then
            strTmp1 = strTmp1 & tmp1 & vbCrLf
        End If
    Loop
    Close #1arrLine1 = Split(strTmp1, vbCrLf)List1.Clear
    Dim strTmp() As String, i As Long
    strTmp = Split(arrLine1(0), ",")
    For i = 0 To UBound(strTmp)
        List1.AddItem Trim(strTmp(i))
    NextEnd SubPrivate Sub List1_Click()
    Dim strTmp As String, i As Long
    strTmp = LCase("start_" & List1.Text)
    List2.Clear
    For i = 1 To UBound(arrLine1)
        If LCase(Trim(arrLine1(i))) = strTmp Then
            List2.AddItem arrLine1(i + 1)
            Exit For
        End If
    Next
    End SubPrivate Sub List2_Click()
    Dim strTmp As String, i As Long
    strTmp = List2.TextFor i = 1 To UBound(arrLine1)
        If LCase(Trim(arrLine1(i))) = LCase(Trim(strTmp)) Then
            Text1.Text = arrLine1(i + 1)
            Text2.Text = arrLine1(i + 2)
            Exit For
        End If
    Next
    End Sub
      

  2.   

    代码写完后想了想,貌似不完善。
    没有考虑不同的
    START_X
    END_X
    中间若有重复数据的情况吃饭去了哦
      

  3.   

    List2_Click()这样修改一下
    Private Sub List2_Click()
    Dim strTmp As String, i As Long
    strTmp = LCase("start_" & List1.Text)For i = 1 To UBound(arrLine1)
        If LCase(Trim(arrLine1(i))) = strTmp Then
            Text1.Text = arrLine1(i + 2)
            Text2.Text = arrLine1(i + 3)
            Exit For
        End If
    Next
    End Sub
      

  4.   

    谢谢你的程序,基本OK,可是这样没达到我的意图,不好意思
    我的意思是list1显示了a,b,c了,在list1中选择了a,会在list2中显示1,4,7,而不是第一行的数据,准确的说是显示第一列的数据,不好意思,在text1,和text2中显示相应的2,5,8和3,6,9。谢谢!
    不过还是谢谢,我是初学,不好意思!
      

  5.   

    应该说是这样:
    在list2中显示1,4,7,然后选择1,在text1,和text2中显示相应的2和3。以此类推!
      

  6.   

    在窗口画三个text
    两个list
    代码如下:
    Dim a() As String, n%
    Private Sub List1_Click()
    For j = 0 To UBound(a)
     If List1.Selected(j) = True Then
      List2.Clear
      List2.AddItem 1 * 10 ^ j
      List2.AddItem 4 * 10 ^ j
      List2.AddItem 7 * 10 ^ j
      n = j
     End If
    Next j
    End SubPrivate Sub List2_Click()
     If List2.Selected(0) = True Then
      Text2.Text = 2 * 10 ^ n
      Text3.Text = 3 * 10 ^ n
     End If
     If List2.Selected(1) = True Then
      Text2.Text = 5 * 10 ^ n
      Text3.Text = 6 * 10 ^ n
     End If
     If List2.Selected(2) = True Then
      Text2.Text = 8 * 10 ^ n
      Text3.Text = 9 * 10 ^ n
     End If
    End SubPrivate Sub Text1_Change()
    str1 = Text1.Text
    a = Split(str1, ",")
    List1.Clear
    For i = 0 To UBound(a)
      List1.AddItem a(i)
    Next i
    End Sub
      

  7.   

    我是说读取text文本文件,数据是随文本文件的改变而改变的,不是程序里给定的
      

  8.   

    数据是在文本文件里输入的,就是text1中,比如输入“a,b,c”以后,再输入“d”以后是改变的
      

  9.   

    完全不是我要的结果,前面gabazi同志写的是不错的,只是没分列,你找个要在text1中输入数据的,我的数据很庞大的话,程序代码就不得了了,但是我要的结果是数据写在xxx.txt文本文件中,程序打开后读取文本文件的数据,在列表中显示,选择后相应的控件显示相应的数据.
      

  10.   

    这个我是没注意了,你说是要在text文件中读数,我以为你要在Text对象中读数据
      

  11.   

    是啊,有一个txt文件的,里面的数据可能很庞大,如:
    qw,dfg,x,Hstart_qw
    L20×20×3,0.899
    L20×20×4,1.145
    L25×25×3,1.124
    L25×25×4,1.459
    L30×30×3,1.373
    L30×30×4,1.786
    L36×36×3,1.656
    end_qwstart_dfg
    C50×37×4.5,5.438
    C63×40×4.8,6.63
    C80×43×5,8.04
    C100×48×5.3,10
    C126×53×5.5,12.31
    end_dfgstart_x
    I100×68×4.5,11.25
    I126×74×5,14.21
    I140×80×5.5,16.88
    I160×88×6,20.5
    I180×94×6.5,24.13
    I200×100×7,27.91
    I200×102×9,31.05
    I200×110×7.5,33.05
    I200×112×9.5,36.5
    end_xstart_H
    H96×100×5×8,16.7
    H100×100×6×10,20.4
    H120×106×12×20,41.8
    H114×120×5×8,19.9
    H120×120×6.5×11,26.7
    H140×126×12.5×21,52.1
    end_H