由于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...如何实现啊??
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...如何实现啊??
并弄几个变量
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
有解决的方案不?最好用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
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
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
b:5,15,0,n...
c:20,6,3.5,n...
这格式是你自己写的,俺没自编。
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
......
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数组只实现哪个元素的值变化记录哪个,没有变化的不重复记录?谢谢
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