trying to get a C5:0.acc value

jaudiel

Member
Join Date
Mar 2011
Location
del rio
Posts
3
i am trying to get the value for a counter in Rslogix500 using VBA , i am using this code but i am getting errors when I run this

Can you give me some guides with the code?

Sub dato()

Dim gApplication As RSLogix500.Application 'Application object Dim gProject As RSLogix500.LogixProject 'LogixProject object Dim gDataFiles As RSLogix500.DataFiles 'DataFiles Collection Dim gDataFile As RSLogix500.DataFile 'DataFile object Dim

valor As String
Set gDataFiles = gProject.DataFiles



val = gDataFiles.GetDataValue("C5:0.ACC")




End Sub

the error i am getting is:
run time error 91
Object variable or with not block set
 
If you go to the debug, do you know where in the routine the error is flagged?

I haven't used VBA in RSLogix before, but it looks to me as if the gProject object is being referenced without being set.

You are trying to Set gDataFiles to gProject.DataFiles, but gProject itself has not been initialized.

You should pass in or set gProject to something, I'm not sure how to do this as I haven't used VBA in RSLogix before.
 
Why in the world are you trying to read the counters current value through the PROGRAMMING software?
Are you trying to get the live value? or just the random value that happens to be in the accumulator the last time the project was saved?
 
yes i need real time counter value

yes i am trying to get the value from the counter while the ladder code is working (that is to say with my plc running in on line mode). the reason is because i am running a durability test (1 million cycles) and i have an application to send an email from VBA with any information, the info that i need is the real time counter ( number of cycles)to say automatically to some people how many cycles and the test status.
 
partial solution

Thanks so much for the answers, those answers helped me to reach this partial solution i am right now getting the value from the counter (wich is the cycles number) using this code

Dim gApplication As RSLogix500.Application 'Application object
Dim gProject As RSLogix500.LogixProject 'LogixProject object
Dim gDataFiles As RSLogix500.DataFiles 'DataFiles Collection
Dim gDataFile As RSLogix500.DataFile 'DataFile object
Private Sub CommandButton1_Click()
' Set the application object to the object returned by CreateObject.
' CreateObject is simply a method provided by Microsoft that creates
' a new registered COM application instance. In this case we start
' RSLogix 5 by using the "RSLogix5.Application" string.
Set gApplication = CreateObject("RSLogix500.Application")
' At this point, if the CreateObject method functioned properly, the
' gApplication object is now a direct reference to the RSLogix5
' Object Model. Any properties or methods that we invoke on this
' object will immediately take effect in RSLogix.
' Immediately set the visible property of the application to 'True'
gApplication.Visible = True
' Assign the AutoSaveInterval value to 3 minutes
gApplication.AutoSaveInterval = 3
' Assign WindowState prop. to lgxWindowStateMaximized enumeration
gApplication.WindowState = lgxWindowStateMaximized
End Sub
Private Sub CommandButton2_Click()
Dim name As String
' Get the currently open project in the application.
Set gProject = gApplication.GetActiveProject
name = gProject.name
MsgBox (name)
End Sub
Private Sub CommandButton3_Click()
On Error GoTo errorHandler
' Upload a project from the processor using the upload method of the
' application object while ignoring prompts, NOT saving the previous
' file, creating new file from the upload (using lgxUploadCreateNew
' enum (see the objectbrowser for more enumerations)), and go online
' (using the lgxGoOnline enum).
' Set the returned object reference to the gProject object.
'24 • RSLogix Automation Interface Reference Manual
Set gProject = gApplication.Upload(True, False, lgxUploadCreateNew, lgxGoOnline)
Exit Sub
errorHandler:
' Upon a caught error decide what to do.
MsgBox "Error: " & Err.Number & vbCrLf & "Description: " & Err.Description
End Sub
Private Sub CommandButton4_Click()
' Quit the application ignoring prompts and not saving changes.
gApplication.Quit True, False
' Eliminate the reference to the application object
Set gApplication = Nothing
End Sub
Private Sub CommandButton5_Click()
Dim value As String
Set gDataFiles = gProject.DataFiles
value = gDataFiles.GetDataValue("C5:0.acc")
cuentas.Text = value
End Sub


the software that you suggested me is an amazing one i downloaded it and i have it right know working (i did a display showing some plc info) this is great and easy!!!!!!!!!!!
 

Similar Topics

Hi All, As a precaution my company has been collecting copies all the HMI and PLC programs. I have recorded copies of most of our sites...
Replies
0
Views
76
I can't seem to get the Panel View Plus 7 standard edition to downgrade to V_11, when I check the AB downloads and compatibility websites for this...
Replies
1
Views
147
Hi I used to be able to launch PLCsim without any problem. Now it tells me " STEP 7 Professional Licence is required to simulate this PLC"...
Replies
15
Views
566
Hello! When trying to load the hardware configuration I get error 0050-133 2 2458, check the diagnostic buffer. When checking the buffer, it says...
Replies
4
Views
207
Back
Top Bottom