I'm reading in energy data from an windfarm via a CSV file. And passing it out in a new CSV file. this file need to have values to it.
But when sometimes the windfarm is offline and the my variables will be empty. So I need a way to see if there are empty and the assign a "0" to it. CSV file values get read by an OPC server so there need to be values in it.
On Error Resume Next
Dim objFSO
Set objFSO = CreateObject("Scripting.FileSystemObject")
Dim objFile, strNewestFile, dtmMax
For Each objFile In objFSO.GetFolder("C:\CSV\Test\CSVOriginal").Files
If objFile.DateLastModified > dtmMax Then
dtmMax = objFile.DateLastModified
strNewestFile = objFile.Path
End If
Next
objFSO.GetFile(strNewestFile).Copy "C:\CSV\Test\CSVFlytt\Data.csv"
Const ForReading = 1
Dim arrCSVData, arrCSVDataOpc(10,1)
Dim strData, X1, Y1, X2, Y2, X3, Y3, X4, Y4, X5, Y5, X6, Y6, X7, Y7, X8, Y8, X9, Y9, X10, Y10, X11, Y11
Dim X20, X21, X22, X23, X24, X25
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile("C:\CSV\Test\CSVFlytt\Data.csv", ForReading)
Do Until objFile.AtEndOfStream
strNextLine = objFile.ReadLine
If Len(strNextLine) > 0 Then
strLine = strNextLine
End If
Loop
objFile.Close
'WScript.Echo strLine
strData = strLine
arrCSVData = Split(strData , ";")
For i = LBound(arrCSVData) To UBound(arrCSVData)
'WScript.Echo arrCSVData(i)
X1 = "Wm2"
Y1 = arrCSVData(2)
X2 = "°C"
Y2 = arrCSVData(4)
X3 = "m/s"
Y3 = arrCSVData(6)
X4 = "VR1 kWh"
Y4 = arrCSVData(9)
X5 = "VR1 W"
Y5 = arrCSVData(18)
X6 = "VR2 kWh"
Y6 = arrCSVData(30)
X7 = "VR2 W"
Y7 = arrCSVData(39)
X8 = "VR3 kWh"
Y8 = arrCSVData(51)
X9 = "VR3 W"
Y9 = arrCSVData(60)
X20 = CSng(Y4)
X21 = CSng(Y6)
X22 = CSng(Y8)
X10 = "Total kWh"
Y10 = (X20 + X21 + Y8)
X23 = CSng(Y4)
X24 = CSng(Y7)
X25 = CSng(Y9)
X11 = "Total W"
Y11 = (X23 + X24 + X25)
Next
arrCSVDataOpc(0,0)= X1
arrCSVDataOpc(0,1)= Y1
arrCSVDataOpc(1,0)= X2
arrCSVDataOpc(1,1)= Y2
arrCSVDataOpc(2,0)= X3
arrCSVDataOpc(2,1)= Y3
arrCSVDataOpc(3,0)= X4
arrCSVDataOpc(3,1)= Y4
arrCSVDataOpc(4,0)= X5
arrCSVDataOpc(4,1)= Y5
arrCSVDataOpc(5,0)= X6
arrCSVDataOpc(5,1)= Y6
arrCSVDataOpc(6,0)= X7
arrCSVDataOpc(6,1)= Y7
arrCSVDataOpc(7,0)= X8
arrCSVDataOpc(7,1)= Y8
arrCSVDataOpc(8,0)= X9
arrCSVDataOpc(8,1)= Y9
arrCSVDataOpc(9,0)= X10
arrCSVDataOpc(9,1)= Y10
arrCSVDataOpc(10,0)= X11
arrCSVDataOpc(10,1)= Y11
arrCSVDataOpc(10,0)= X11
arrCSVDataOpc(10,1)= Y11
Set oFSO = CreateObject("Scripting.FileSystemObject")
Dim filesys, testfile
Set filesys = CreateObject("Scripting.FileSystemObject")
Set testfile = oFSO.CreateTextFile("C:\CSV\Test\OPC\data.csv", True)
testfile.WriteLine X1 & ";" & Y1
testfile.WriteLine X2 & ";" & Y2
testfile.WriteLine X3 & ";" & Y3
testfile.WriteLine X4 & ";" & Y4
testfile.WriteLine X5 & ";" & Y5
testfile.WriteLine X6 & ";" & Y6
testfile.WriteLine X7 & ";" & Y7
testfile.WriteLine X8 & ";" & Y8
testfile.WriteLine X9 & ";" & Y9
testfile.WriteLine X10 & ";" & Y10
testfile.WriteLine X11 & ";" & Y11
testfile.Close
Y1 = iif(arrCSVData(2)="","0",arrCSVData(2))? check the iif functionEmptywhen you say "empty"?IIf()function.