|
发表于 2020-7-29 14:00:01
|
显示全部楼层
偶的一个例子,数据采集的显示函数里增加的把数据添加到excel的文件里的方法!!!供楼主参考!
Sub ShowDigitProc()
Screen.MousePointer = vbHourglass '''''''''''表示等待状态
Dim xls As Object 'Excel格式输出数据
Set xls = CreateObject("Excel.Application")
xls.Visible = True
xls.Caption = "Four Signals"
Set xlbook = xls.Workbooks.Add 'Excel格式输出数据
Dim Row As Integer
Dim Col As Integer
Dim i, j As Integer
Dim channelpot As Integer
Dim ch0(511), ch1(511), ch2(511), ch3(511) As Single
channelpot = (4096 - (4096 Mod ChannelCount)) '原型为:channelpot = (8192 - (8192 Mod ChannelCount))
For i = 0 To ChannelCount - 1
s$ = s$ + "| CH" + Str$(Hist_Header.FirstChannel + i)
Next
Grid.FormatString = s$
s$ = ";"
For i = 0 + m_Offset To ((channelpot / ChannelCount) - 1 + m_Offset)
s$ = s$ + "|" + Str$(i)
Next
Grid.FormatString = s$
'Open "D:\05.txt" For Output As #1' '文本格式读出数据
For Row = 1 To ((4096 - (4096 Mod ChannelCount)) / ChannelCount)
Col = 0 ''''''''''''''''''''''''''可以存取数据了 !!!!!!!!!!!!!
Grid.TextMatrix(Row, Col + 1) = Format(((((InRegionUser((Row - 1) * ChannelCount + Col) Xor &H2000) And &H3FFF) - &H2000) * PoltvalueChange) / 1000, "#.00000")
ch0(511) = Grid.TextMatrix(Row, Col + 1)
ch0(511) = Val(ch0(511))
Text3.Text = ch0(511)
xls.Cells(Row, 1).Value = ch0(511) 'Excel格式输出数据
Col = 1 ''''''''''''''''''''''''''可以存取数据了 !!!!!!!!!!!!!
Grid.TextMatrix(Row, Col + 1) = Format(((((InRegionUser((Row - 1) * ChannelCount + Col) Xor &H2000) And &H3FFF) - &H2000) * PoltvalueChange) / 1000, "#.00000")
ch1(511) = Grid.TextMatrix(Row, Col + 1)
ch1(511) = Val(ch1(511))
Text4.Text = ch1(511)
xls.Cells(Row, 2).Value = ch1(511) 'Excel格式输出数据
Col = 2 ''''''''''''''''''''''''''可以存取数据了 !!!!!!!!!!!!!
Grid.TextMatrix(Row, Col + 1) = Format(((((InRegionUser((Row - 1) * ChannelCount + Col) Xor &H2000) And &H3FFF) - &H2000) * PoltvalueChange) / 1000, "#.00000")
ch2(511) = Grid.TextMatrix(Row, Col + 1)
ch2(511) = Val(ch2(511))
Text5.Text = ch2(511)
xls.Cells(Row, 3).Value = ch2(511) 'Excel格式输出数据
Col = 3 ''''''''''''''''''''''''''可以存取数据了 !!!!!!!!!!!!!
Grid.TextMatrix(Row, Col + 1) = Format(((((InRegionUser((Row - 1) * ChannelCount + Col) Xor &H2000) And &H3FFF) - &H2000) * PoltvalueChange) / 1000, "#.00000")
ch3(511) = Grid.TextMatrix(Row, Col + 1)
Text6.Text = ch3(511)
xls.Cells(Row, 4).Value = ch3(511) 'Excel格式输出数据
'Write #1, ch0(511), ch1(511), ch2(511), ch3(511)' '文本格式读出数据
'Draw_Click
'Picture2.PSet (ch0(511), ch2(511)), RGB(255, 0, 255)
Next
'Close #1' '文本格式读出数据
Screen.MousePointer = vbDefault '''''''''''''表示形状由对象确定
End Sub |
|