VBA for rsview32

wjfisherjr

Member
Join Date
Jul 2005
Location
New Jersey
Posts
1
I am trying to use vba for the first time. I have search for a solution and found some code and changed it to work with my application. But I am still having a few problems. The code works great except I want it to print the column labels and then move down a row and print tag info. Can anyone help:

Here is the code:

Public Sub WriteCSVLogFile()
'Atmosfear Daily Counter
Dim AFDT As Tag
'Rollies daily counter
Dim RODT As Tag
'Rocking Tug daily counter
Dim RTDT As Tag
'Flitzer daily counter
Dim FLDT As Tag
'Sea Serpent daily counter
Dim SSDT As Tag
Dim LogDate As Date
Dim LogFile As Integer
Dim HeaderTrack As Integer
Dim HeaderPrint As Integer
On Error GoTo catch
MkDir ("F:\April\PLC Backups\Daily_Dispatch_Counts")
Check:
'Check to see if the header needs to be inserted.
'HeaderTrack is an Integer bit that is set to 0 if it is 12:00 AM, otherwise set = 1.
If ((Format$(Time, "hh:mm:ss") >= #12:00:00 AM#) And (Format$(Time, "hh:mm:ss") <= #12:01:00 AM#)) Or (HeaderPrint = 0) Then
HeaderTrack = 1
Else: HeaderTrack = 0
End If
Set AFDT = gProject.TagDb("Atmosfear\Daily_Counter")
Set RODT = gProject.TagDb("Rollies\Daily_Dispatch")
Set RTDT = gProject.TagDb("RockingTug\Daily_Dispatch")
Set FLDT = gProject.TagDb("Flitzer_Daily_Dispatch")
Set SSDT = gProject.TagDb("SeaSerpent\Daily_Dispatch_Counter")
'Set LogDate equal to current date function.
LogDate = Date
'Get available file number
LogFile = FreeFile
'Open File for writing to and name file with format date.csv
Open "F:\April\PLC Backups\Daily_Dispatch_Counts\" & Format$(LogDate, "mmddyy") & ".csv" For Append As #LogFile
'Insert the Header into the csv file between 12:00 and 12:01 AM (or next time program runs) and then insert the data in the correct columns.
If HeaderTrack = 1 Then
Print #LogFile, " TIME"; ","; _
"Atmosfear"; ","; _
"Rollies"; ","; _
"Rocking Tug"; ","; _
"Flitzer"; ","; _
"Sea Serpent"; ","; _
'Insert data into column if the header was just inserted
Print #LogFile, Format$(Time, "hh:mm:ss"); ","; _
Format(AFDT.Value, "###,###"); ","; _
Format(RODT.Value, "###,###"); ","; _
Format(RTDT.Value, "###,###"); ","; _
Format(FLDT.Value, "###,###"); ","; _
Format(SSDT.Value, "###,###"); ","; _
HeaderPrint = 1
Else
'If time is anything other than 12:00 and 12:01 midnight just insert the data
Print #LogFile, Format$(Time, "hh:mm:ss"); ","; _
Format(AFDT.Value, "###,###"); ","; _
Format(RODT.Value, "###,###"); ","; _
Format(RTDT.Value, "###,###"); ","; _
Format(FLDT.Value, "###,###"); ","; _
Format(SSDT.Value, "###,###"); ",";
End If
Close #LogFile
'If the directory already exists, skip to the next line
'Error 75 is directory already created or exists.
catch: 'Error handling routine
If Err.Number = 75 Then
Err.Clear
GoTo Check
Else
If Err.Number = 4170 Then
'roErrorTagEvent (4170) - an error occurred while waiting for the operation to complete
Err.Clear
GoTo Check
End If 'End errror #4170
Err.Clear
End If 'End errror handling
End Sub


Thanks in advance
 

Similar Topics

Good friends, I'm new to the forum, I'm working with RSview32, someone can help me how to make a macro in VBA, to save some data in Excel. to...
Replies
6
Views
1,955
We were given RSView32 project files, for quoting, that will be converted to FTView SE. Unfortunately the project has VBA references that were...
Replies
9
Views
4,324
Hi, I got a RSview32 project from site with VBA scripts and trying to run on my local machine to make some graphical changes. VB scripts are used...
Replies
6
Views
3,498
Please somebody upload this manual on another site or forward me 51770 - Sample VBA: Exercise in migrating an RSView32 application with VBA to...
Replies
8
Views
4,914
Hello all, New to the forums here and glad to find this oasis of RSView/FactoryTalk info! I have a basic VB question I hope can be answered...
Replies
4
Views
2,311
Back
Top Bottom