由于label数组的Caption里的内容是不断变化的,如何按格式自动保存其中的内容?例如:
a label(0).caption=12    b label(1).caption=5      c label(2).caption=20
一段时间后变化为:
a label(0).caption=7    b label(1).caption=15     c label(2).caption=6
在一段时间后变化为:
a label(0).caption=2    b label(1).caption=0      c label(2).caption=3.5
再过后........
a label(0).caption=m   b label(1).caption=n      c label(2).caption=f需要将上述保存在一个.txt记事本文档里,格式如下:
a:17,7,2,m...
b:5,15,0,n...
c:20,6,3.5,n...如何实现啊??

解决方案 »

  1.   

    我刚才试了一下,用代码label1.caption = xxx时,vb不能捕获WM_SETTEXT消息,现有比较直白的轮询办法了。弄一个timer
    并弄几个变量
    dim olds( 0 to xx) as string
    dim news( 0 to xx) as string
    dim history( 0 to xx ) as string在timer中
    dim i as long
    for i = 0 to xx
        news(i)=label(i).caption
        if news(i) <> olds(i) then
            history(i)=history & "," & news(i)
            olds(i)=news(i)
        endif
    next i
      

  2.   

    楼上的VB.NET代码不好用!
    有解决的方案不?最好用VB6.0的代码!
    我原先使用如下代码,出现的保存格式是
    a 17
    b 5
    c 20
    a ..
    b ..
    c .. 而不是要求的 a:17,7,2,m... 
                     b:5,15,0,n... 
                     c:20,6,3.5,n...
    原先的代码为:
    Private Sub Timer1_Timer()
    Dim i  As Long
     Open App.Path + "\data.ini" For Output As #1
        For i = 0 To Label1.Count - 1
            Print #1, ID(i); Label1(i).Caption 'ID就是a,b,c
        Next
        Close #1
        
      End Sub   
      

  3.   

    别扭,为什么非要将数据如此排列?Private Sub _Change()
    Dim a As String, b As String, c As String
      If Dir(App.Path & "\yourfile.txt") > "" Then
        Open App.Path & "\yourfile.txt" For Input As #1
        Line Input #1, a
        Line Input #1, b
        Line Input #1, c
        Close #1
      End If  a = a & IIF(a = "", "a:", ",") & Label(0)
      b = b & IIF(b = "", "b:", ",") & Label(1)
      c = c & IIF(c = "", "c:", ",") & Label(2)
      Open App.Path & "\yourfile.txt" For Input As #1
      Print #1, a
      Print #1, b
      Print #1, c
      Close #1
    End Sub
      

  4.   

    Private Sub Label_Change() 
      

  5.   

        a   =   a   &   IIF(a   =   "",   "a:",   ",")   &   Label(0) 
        b   =   b   &   IIF(b   =   "",   "b:",   ",")   &   Label(1) 
        c   =   c   &   IIF(c   =   "",   "c:",   ",")   &   Label(2) 
        Open   App.Path   &   "\yourfile.txt"   For   Output   As   #1 
        Print   #1,   a 
        Print   #1,   b 
        Print   #1,   c 
        Close   #1 
      

  6.   

    那代码就是个示意,说明的是俺对这个问题的想法,并不见得就是无误执行的再说那就是vb6.0的代码,不是vb.net的还有就是a:17,7,2,m... 
    b:5,15,0,n... 
    c:20,6,3.5,n... 
    这格式是你自己写的,俺没自编。
      

  7.   

    楼主,不如这样:Private Sub Label_Change() 
        Open App.Path & "\yourfile.txt" For Append As #1 
        If LOF(1) = 0 Then Print #1, "a", "b", "c" 
        Print #1, Label(0), Label(1),  Label(2)
        Close #1 
    End Sub出来的结果是:
    a      b      c
    17     5      20
    7      15     6
    2      0      3.5
    m      n      n
    ......
      

  8.   

    楼上好人,你的能实现如下结果:很高兴!
    a      b      c
    17     5      20
    7      15     6
    2      0      3.5
    m      n      n
    ......
    但label1为控件数组,它的change事件它所有的元素都发生变化,假如label(1)的值没变化
    而label(2)变化,它也触发change事件,label(1)的值重复没变化的再记录了一次,能否实现
    对于label数组只实现哪个元素的值变化记录哪个,没有变化的不重复记录?谢谢
      

  9.   

    来回不断的写文件,效率有代考虑!
    Option Explicit
    Dim str()         As String
    Dim i               As Integer
    Const strFilePath   As String = "D:\test.txt"
    Const intNUM        As Integer = 2Private Sub Form_Load()
        ReDim str(intNUM) As String
        For i = 0 To intNUM
            str(i) = Chr$(97 + i) & ":"
        Next
    End SubPrivate Sub Label1_Change(Index As Integer)
        Dim i As Integer
        str(Index) = str(Index) & Label1(Index).Caption & ","
        If Dir(strFilePath) <> "" Then Kill (strFilePath)
        Open strFilePath For Output As #1
        For i = 0 To intNUM
            Print #1, str(i)
        Next
        Close #1
    End Sub
    Private Sub Timer1_Timer()
        Dim intXx As Integer
        intXx = Fix(Rnd * 3)  '0 ~ 2
        Label1(intXx) = CInt(Rnd * 10)
    End Sub
      

  10.   

    ZOU_SEAFARER:您好!可以用vb6.0写不?我的开发环境是6.0,我好调试阿!
      

  11.   

    呵呵,meilidexue     我遇到高手了 !!!惭愧惭愧