Using VBA to create Par files in FactoryTalk

ballack

Member
Join Date
Jul 2013
Location
TX
Posts
30
Hello,
I came up with an idea to use an excel macro to create a bunch of parameter files for a project I'm currently working on. I managed to populate the \PAR directory with the files I needed, I added them to my project but whenever I try to compile and go to run time, I get an error that says: "The syntax in the line #1=V400 is incorrect", anyone seen this before?
 
Yes I encountered this problem years ago. You have to use Unicode character encoding otherwise it won't work.

Sorry I don't have a code reference for you right now.
 
Yes, I open the files in notepad and in FT and both read just fine. When I try to create the runtime file, however, I get an error saying that the syntax is incorrect, but I have checked it again and again and I don´t see anything wrong.
 
As Paully's5.0 said. Please ensure that you are using Unicode for encoding in the file.
Open with notepad to view the file saved as test.PAR 'Encoding = Unicode '
Note: Notepad defaults to ANSI

Regards,
 
I have checked and unicode is set as the file type. Has anyone actually done this succesfully, maybe you could post the vba code.
 
Inspect your .par files using a Hex editor. Application like notepad add a Byte Order Mask (BOM) at the beginning of the file, and I suppose your Excel code is doing that. Parameter files have no BOM.

parameter.PNG
 
It appears you are correct, inspecting the file, I do have a BOM in the first line. Now the question is, how could I save the file without it? Here´s the code I wrote in VBA:

Set fs = CreateObject("Scripting.FileSystemObject")

ParFileName = Cells(1, 3) & "\" & Cells(2, 1) & Cells(2, 2) & ".PAR"
Set File = fs.CreateTextFile(ParFileName, True, True)
File.WriteLine ("#1=" + Cells(3, 4))
File.WriteLine ("#2=" + Cells(3, 5))
 
Pretty sure this was the code I had to add, I didn't paste all my code to generate the contents of the file, just the section that I added to save the file properly. Been a few years since I did this, to my knowledge it works.

Code:
    Open sFile For Binary Access Write As #1
    Dim sText As String
    sText = sText1 & vbCrLf & sText2
    Dim buffer() As Byte: buffer = sText
    Put #1, , buffer
    Close #1
 
Haven't done it from vba in excel, but I've done something similar in FT VBA dynamically creating Par files at runtime in an SE app. I had problems with fs.writefile and went old school with open("file name" as #1 for append) and then print #1, blah blah. SE used the par files without complaint.

Incidentally in SE the par files need not be added to the project to utilize at runtime. If they exist in the \par directory it finds them and uses them. I imagine ME would need them added though as it "compiles" a runtime. But I would imagine open in append mode and printing to the file will solve the issue.
 
Haven't done it from vba in excel, but I've done something similar in FT VBA dynamically creating Par files at runtime in an SE app. I had problems with fs.writefile and went old school with open("file name" as #1 for append) and then print #1, blah blah. SE used the par files without complaint.

Incidentally in SE the par files need not be added to the project to utilize at runtime. If they exist in the \par directory it finds them and uses them. I imagine ME would need them added though as it "compiles" a runtime. But I would imagine open in append mode and printing to the file will solve the issue.

Do you have an example of the vba code? Trying to perform the exact same function using dynamic parameter files.

Thanks
 
Do you have an example of the vba code? Trying to perform the exact same function using dynamic parameter files.

Thanks

Here ya go.

Private Sub CreatePar()
fname = "c:\users\public\documents\rsview enterprise\se\hmi projects\P1_CR1\PAR\test.par"
Open fname For Append As #1
Print #1, "#1=TEST_TAG_1"
Print #1, "#2=TEST_TAG_2"
Close #1
End Sub

Private Sub Button2_Released()
CreatePar
End Sub​

As I mentioned before, because ME essentially 'Compiles' a runtime application you won't be able to call parameter files at runtime that aren't included in the project beforehand. But with SE it just looks in the \PAR directory for a file with that filename. Of course it must have a .par extension.

But the code above does create a valid parameter file that can be called. I've included two simple displays that I used to test the code and confirm that it works. Look at the VBA code of the 'Untitled' display to see the tag substitution's and create those tags to test this. It's raw code that you probably wouldn't want to use in a live application because I hard coded the paths, and there is no error checking and such but it should give you a good idea of how to do what you're wanting.

If you want to test this, load 'Untitled' first then click the button to create a par file, then click the other button to launch the second display with the par file you created.
 
Hello,
I came up with an idea to use an excel macro to create a bunch of parameter files for a project I'm currently working on. I managed to populate the \PAR directory with the files I needed, I added them to my project but whenever I try to compile and go to run time, I get an error that says: "The syntax in the line #1=V400 is incorrect", anyone seen this before?

Is the problem already solved? Because I have the same problem... When I create a Test-Application comes the error "The syntax in the line #1=Test is incorrect"
 
Is the problem already solved? Because I have the same problem... When I create a Test-Application comes the error "The syntax in the line #1=Test is incorrect"
The example code in my post above works provided the tag referenced is defined in the tag database or points to a fully qualified PLC direct tag reference.

Also just to be clear, If you are not automating the creation of Parameter files with VBA then of course the syntax would be incorrect as Parameter files will not work if there are Quotes around the substitution lines. VBA prints what's inside the quotes into a file. If you are just creating Parameter files manually then you would only need;

#1=TEST_TAG

But TEST_TAG would still need to be defined in the Tag Database unless you use a fully qualified Direct Tag Reference.
 

Similar Topics

Hi, Can someone guide me through how to use FactoryTalk SE VB script to open communication with SQL Server? which command I can use? Are there...
Replies
2
Views
2,248
Hello Every one, I need a help on vba code for getting data from MSSQL server 2014 to display in FTview SE client version 12 . Thanks. Please...
Replies
4
Views
1,751
Hi, how can i use a defined Tag in HMI Tags (for exampele dintTag ) in VBA code by a display. i am using FactoryTalk SE thanx
Replies
1
Views
2,205
I am trying to open a single display for multiple messages. I understand that I can use parameters to load different messages etc but would like...
Replies
0
Views
1,217
Hello, I am looking for help writing to PLC tags from Excel. I am using Factory Talk Gateway as an OPC server and Excel VBA to write out to an...
Replies
5
Views
3,017
Back
Top Bottom