Using VBA in RSView SE question.

briana banks

Member
Join Date
Jul 2005
Posts
242
Hi all

Can someone please show me a small sample project on how to store data
using VBA on either a SQL Database, or an Access (Jet) database for storing and maintaining data(few rows including time and date)
from RSView project.

I know VBA and SQL but how use them in RSView SE project?


Many Thanks.
 
Last edited:
Hi,

It's not too bad. You need to use the MDAC (Microsoft Data Acess Objects) ADO library to do it (version 2.7 I think is current). These are included with RSView SE, you can get them by opening the VBA editor, selecting "references" from the menu (I think) and looking for the ADO libraries. Basically, you want to be able to create "recordset" objects in your code that are linked to a database and that you can run queries on. Select everything that looks useful and you should be OK :)

Once you have done that, you need to create a system ODBC system DSN (Data Source Name) connection to your database. This will give your programs an interface to a selected database via ODBC drivers you configure (Access drivers etc).

You can get the ODBC toolbox by selecting Start --> control panel --> Adminstrative tools --> ODBC. Select the system DSN tab, and add a new Microsoft Access driver (substitute whatever DB you are using of course). Give your new data source a name (you will use this in your VBA) and link it to the database you want to use. You now have a programatic interface the SQL database that you can use to access data from another program.

Unfortunately, I don't have easy access to the source code but the basic form of your VBA code is this:

1. Declare a recordset object from the ADO libraries you have just created to hold the results of any query you run on the external database.
2. Run a SQL query (SELECT * TABLE_OR_QUERY_NAME, for example) on the database linked by the ODBC connection.
3.The syntax for address fields in this query is similar to the following:
Localvariable = recordsetname!Fieldname
This will allow you to read out what is stored in the database.

Have a look on the internet for sample VBA ADO source code for accessing a SQL database and this should complete your picture. Here's a start:
http://samples.gotdotnet.com/quickstart/howto/

Good luck :D
 
how do i get the value of tags ?

Hi and thanks for replying.

how do i get the value of tags or access the tag using VBA?
e.g. instead of using the action tab from the for push button

thanks
 
briana banks said:
Hi and thanks for replying.

how do i get the value of tags or access the tag using VBA?
e.g. instead of using the action tab from the for push button

thanks

You don't, from the 'Action' tab. Two ways to do that offhand, would be to define a global tag group, and add that tag to it. Then it can be accessed from VBA. This method assumes that you have a global window open all the time (onscreen or off, I use a 'Titlebar' as my main VBA and global repository, as it never closes).

The other way, is just open the 'Properties' for the Button/Numeric display, input, whatever, and select 'Expose to VBA'. Then it will be directly available in the VBA module for that display.
 
Hi
sorry for not understanding you.
how do i obtain a tag value (both ways)?
how can i gain access to each one of all HMI tags
what is the code syntax?

Thanks
 
Last edited:
I sent you a PM Briana, shoot me your email, and I'll send you some sample code (well, working code) from View SE that logs information to one of our databases.
 
Same issue here...

Hi, I realize this is an old topic, but I am currently having the same difficulty with accessing tags fom VBA. If you don't mind, RDRAST, could you forward some of the same info that you sent to Briana? Much thanks in advance and regards,

Dale
 



Basics for creating global tag groups in RSView SE:


In the global declarations section of the VBA module:

Public HMITagGlobal As Tag ' Reserve space to access a tag
Public HMIGroupGlobal As TagGroup ' Reserve space for the tag group
Public TagsInError As StringList ' Reserve space for error results
Public Results As Boolean ' Reserve space for status outputs



In the 'AnimationStart' event for your display (best if used in a never-closed global display):

' Note that the number after the area name is the polling rate for all tags in the group (update rate) in msec.
Set HMIGroupGlobal = Application.CreateTagGroup(Me.AreaName, 500) 'Create The TagGroup Object


Once the tag group has been created, you have to add tags to it that you wish it to monitor:

HMIGroupGlobal.Add ("[DataServer]Client_Watchdog.ACC")
HMIGroupGlobal.Add ("[DataServer]G63_Recipe")
HMIGroupGlobal.Add ("TagFolder\FormulaName")
HMIGroupGlobal.Add ("TagFolder\FormulaDesc")
HMIGroupGlobal.Add ("[DataServer]Campaign.Num_Batches")
HMIGroupGlobal.Add ("TagFolder\Bin1")


Those are actual tags. The [bracketed] tags are direct references to the RSLinx I/O Server.
The tags without brackets are defined in the View SE Tag Database.


To assign values to the tags in the global group, do something like:

' Retrieve tag to work with from the group, and put it in our reserved tag space
Set HMITagGlobal = HMIGroupGlobal.Item("TagFolder\FormulaName")

' Now write new text to the tag "TagFolder\FormulaName" by assigning it from a field on our VBA Form:
HMITagGlobal.PendingWriteValue = frm_Insulation_Campaing.cbo_Formula.Text


' Do the same thing with a numeric tag in the PLC.. First, get it into tag object to use:
Set HMITagGlobal = HMIGroupGlobal.Item("[DataServer]PolymerScale.PlymrWtSetpt")

' Then set it to a value (which will be written to the PLC)
HMITagGlobal.PendingWriteValue = 0


' When you are ready to write the actual values, you command the tag group to do it:
Results = HMIGroupGlobal.WritePendingValues(TagsInError)



Now, to retrieve tag values, you do something like:

' Retrieve tag to work with from group, and put it into our working tag space
Set HMITagGlobal = HMIGroupGlobal.Item("TagFolder\FormulaName")

'The data held in the tag is accessed through the .Value property:
CampaignFormula = HMITagGlobal.Value



 
Microsoft ADO Data Control 6.0 Does Not Connect to My SQL???

Hi,

Microsoft ADO Data Control 6.0 Does Not Connect to My SQL???
Can someone help me because my Adodc is not communicating to my SQL pack?

1 - My factorytalk 8.0 when I fetched the Object - Active Control - Microsoft ADO Data Control 6.0 - gave me an error - License to install this I installed Microsoft Studio Visual Basic 6.0

2 - Done This I searched again for my Microsoft ADO Data Control 6.0 and my DataGrid.
I do all his configuration looking for the Bank to squeeze table in Test as if it had everything ok.

Does anyone know what may be happening that I can not connect it to my SQL?

Script Grid Inicializaca.jpg
 

Similar Topics

In RsView, I have a "configuration" button which aborts all graphic displays and re-loads(displays) them at particular locations in the main...
Replies
1
Views
4,954
First let me post the reason. I need to have RSView interact with an external application tying the alarms to an external logging application...
Replies
11
Views
11,342
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
Back
Top Bottom