2017년 7월 19일 수요일
데이터수집_엑셀저장
///////////////////설정시간 데이터수집
Sub OutputFile()
flagD = GetTagVal("save_start")
if flagD = 1 then
start_time$ = GetTagVal("시작시간")
SetTagVal "start_time", start_time$
else
start_time$ = GetTagVal("start_time")
end_time$ = GetTagVal("끝시간")
intval = DateDiff("s", start_time$, end_time$)
SetTagVal "interval", cstr(intval)
FileName$ = "D:\EXCEL\" & TimeStr(44) & ".xls"
FileOld$ = "D:\EXCEL\Ex.xls"
If FileExists(FileName$) then
else
FileCopy FileOld$, FileName$
end if
Set XelApp = CreateObject("Excel.Application")
Set XelFile = XelApp.Workbooks.Open(FileName$)
Set ws = XelFile.sheets.item("sheet1")
Cell_Cnt = 1
ws.Cells(Cell_Cnt,1) = "시간"
ws.Cells(Cell_Cnt,2) = "ANA1"
ws.Cells(Cell_Cnt,3) = "ANA2"
for i=1 to intval
setDate$ = DateAdd("s",i,start_time$)
hh$ = hour(setDate$)
mm$ = minute(setDate$)
ss$ = second(setDate$)
nowTime$ = hh$ & "시" & mm$ & "분" & ss$ & "초"
ws.Cells(Cell_Cnt+i,1) = nowTime$
ws.Cells(Cell_Cnt+i,2) = DLogVal("ANA1", nowTime$)
ws.Cells(Cell_Cnt+i,3) = DLogVal("ANA2", nowTime$)
next i
ws.Calculate
XelFile.Save
XelApp.Quit
end if
End Sub
///////////////////실시간 데이터수집
Sub OutputFile2()
flagD = GetTagVal("save_start2")
if flagD = 1 then
start_time$ = now()
SetTagVal "start_time2", start_time$
else
start_time$ = GetTagVal("start_time2")
end_time$ = now()
intval = DateDiff("s", start_time$, end_time$)
SetTagVal "interval", cstr(intval)
FileName$ = "D:\EXCEL\" & TimeStr(44) & ".xls"
FileOld$ = "D:\EXCEL\Ex.xls"
If FileExists(FileName$) then
else
FileCopy FileOld$, FileName$
end if
Set XelApp = CreateObject("Excel.Application")
Set XelFile = XelApp.Workbooks.Open(FileName$)
Set ws = XelFile.sheets.item("sheet1")
Cell_Cnt = 1
ws.Cells(Cell_Cnt,1) = "시간"
ws.Cells(Cell_Cnt,2) = "ANA1"
ws.Cells(Cell_Cnt,3) = "ANA2"
for i=1 to intval
setDate$ = DateAdd("s",i,start_time$)
hh$ = hour(setDate$)
mm$ = minute(setDate$)
ss$ = second(setDate$)
nowTime$ = hh$ & "시" & mm$ & "분" & ss$ & "초"
ws.Cells(Cell_Cnt+i,1) = nowTime$
ws.Cells(Cell_Cnt+i,2) = DLogVal("ANA1", nowTime$)
ws.Cells(Cell_Cnt+i,3) = DLogVal("ANA2", nowTime$)
next i
ws.Calculate
XelFile.Save
XelApp.Quit
end if
End Sub
피드 구독하기:
댓글 (Atom)
댓글 없음:
댓글 쓰기